From dabdc0ab34a162a958287f1cb14419e0430b8de1 Mon Sep 17 00:00:00 2001 From: moanos Date: Thu, 30 May 2024 15:49:32 +0200 Subject: [PATCH] feat: Add animal cards to adoption notice detail --- src/fellchensammlung/forms.py | 13 +++++++++++++ .../details/detail_adoption_notice.html | 10 +++++++++- src/fellchensammlung/urls.py | 2 ++ src/fellchensammlung/views.py | 19 ++++++++++++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/fellchensammlung/forms.py b/src/fellchensammlung/forms.py index 56b8cbc..6805aac 100644 --- a/src/fellchensammlung/forms.py +++ b/src/fellchensammlung/forms.py @@ -41,6 +41,19 @@ class AdoptionNoticeForm(forms.ModelForm): fields = ['name', "group_only", "further_information", "description", "searching_since"] +class AnimalForm(forms.ModelForm): + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.helper = FormHelper() + self.helper.form_class = 'form-animal' + self.helper.add_input(Submit('save-and-add-another-animal', _('Speichern und weiteres Tier hinzufügen'))) + self.helper.add_input(Submit('save-and-finish', _('Speichern und beenden'))) + + class Meta: + model = Animal + fields = ["name", "date_of_birth", "species", "sex", "description"] + + class ImageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html index 0cbbd52..73e7f97 100644 --- a/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html +++ b/src/fellchensammlung/templates/fellchensammlung/details/detail_adoption_notice.html @@ -5,7 +5,8 @@ {% block content %}

{{ adoption_notice.name }}

- {% translate 'Bearbeiten' %} + {% translate 'Bearbeiten' %}
@@ -37,6 +38,13 @@ {% endif %}

+
+ {% for animal in adoption_notice.animals %} + {% include "fellchensammlung/partials/partial-animal-card.html" %} + + {% endfor %} +
+ {% include "fellchensammlung/partials/partial-comment-section.html" %} {% endblock %} diff --git a/src/fellchensammlung/urls.py b/src/fellchensammlung/urls.py index a36277f..bee1682 100644 --- a/src/fellchensammlung/urls.py +++ b/src/fellchensammlung/urls.py @@ -17,6 +17,8 @@ urlpatterns = [ path("vermittlung//", views.adoption_notice_detail, name="adoption-notice-detail"), # ex: /adoption_notice/7/edit path("vermittlung//edit", views.adoption_notice_edit, name="adoption-notice-edit"), + # ex: /adoption_notice/2/add-animal + path("vermittlung//add-animal", views.adoption_notice_add_animal, name="adoption-notice-add-animal"), # ex: /search/ path("suchen/", views.search, name="search"), diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index 872da5f..5fb0a14 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -13,7 +13,7 @@ from notfellchen import settings from fellchensammlung import logger from fellchensammlung.models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \ Member -from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm +from .forms import AdoptionNoticeForm, ImageForm, ReportAdoptionNoticeForm, CommentForm, ReportCommentForm, AnimalForm from .models import Language @@ -101,6 +101,23 @@ def add_adoption(request): form = AdoptionNoticeForm() return render(request, 'fellchensammlung/forms/form_add_adoption.html', {'form': form}) +@login_required +def adoption_notice_add_animal(request, adoption_notice_id): + if request.method == 'POST': + form = AnimalForm(request.POST, request.FILES) + + if form.is_valid(): + instance = form.save(commit=False) + instance.adoption_notice_id = adoption_notice_id + instance.save() + form.save_m2m() + if True: + return redirect(reverse("adoption-notice-detail", args=[instance.pk])) + else: + return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html') + else: + form = AnimalForm() + return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form}) @login_required def edit_adoption_notice(request, animal_id):