feat: Add form to add images to adoption notices and animals
This commit is contained in:
parent
a364287a38
commit
f1dc3fde4c
@ -72,11 +72,20 @@ class AnimalForm(forms.ModelForm):
|
||||
|
||||
class ImageForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
if 'in_flow' in kwargs:
|
||||
in_flow = kwargs.pop('in_flow')
|
||||
else:
|
||||
in_flow = False
|
||||
super().__init__(*args, **kwargs)
|
||||
self.helper = FormHelper()
|
||||
self.helper.form_id = 'form-animal-photo'
|
||||
self.helper.form_class = 'card'
|
||||
self.helper.form_method = 'post'
|
||||
if in_flow:
|
||||
self.helper.add_input(Submit('save-and-add-another', _('Speichern und weiteres Foto hinzufügen')))
|
||||
self.helper.add_input(Submit('submit', _('Speichern')))
|
||||
else:
|
||||
self.helper.add_input(Submit('submit', _('Submit')))
|
||||
|
||||
class Meta:
|
||||
model = Image
|
||||
|
@ -0,0 +1,17 @@
|
||||
{% extends "fellchensammlung/base_generic.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block content %}
|
||||
<p>
|
||||
{% blocktranslate %}
|
||||
Lade hier ein Foto hoch - wähle den Titel wie du willst und mach bitte eine Bildbeschreibung,
|
||||
damit die Fotos auch für blinde und sehbehinderte Personen zugänglich sind.
|
||||
{% endblocktranslate %}
|
||||
<p><a class="btn" href="https://www.dbsv.org/bildbeschreibung-4-regeln.html">{% translate 'Anleitung für Bildbeschreibungen' %}</a></p>
|
||||
</p>
|
||||
<div class="container-form">
|
||||
{% crispy form %}
|
||||
</div>
|
||||
{% endblock %}
|
@ -9,7 +9,7 @@
|
||||
Bitte mach dich zunächst mit unseren Regeln vertraut. Dann trage hier die ersten Informationen ein.
|
||||
Du bekommst in einem weiteren Schritt die Möglichkeit einzelne Tiere zu deiner Vermittlung hinzuzufügen und
|
||||
Fotos hochzuladen.
|
||||
</p>
|
||||
{% endblocktranslate %}
|
||||
</p>
|
||||
{% crispy form %}
|
||||
{% endblock %}
|
@ -13,10 +13,14 @@ urlpatterns = [
|
||||
path("tier/<int:animal_id>/", views.animal_detail, name="animal-detail"),
|
||||
# ex: /animal/5/edit
|
||||
path("tier/<int:animal_id>/edit", views.animal_edit, name="animal-edit"),
|
||||
# ex: /animal/5/add-photo
|
||||
path("tier/<int:animal_id>/add-photo", views.add_photo_to_animal, name="animal-add-photo"),
|
||||
# ex: /adoption_notice/7/
|
||||
path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
|
||||
# ex: /adoption_notice/7/edit
|
||||
path("vermittlung/<int:adoption_notice_id>/edit", views.adoption_notice_edit, name="adoption-notice-edit"),
|
||||
# ex: /vermittlung/5/add-photo
|
||||
path("vermittlung/<int:adoption_notice_id>/add-photo", views.add_photo_to_adoption_notice, name="adoption-notice-add-photo"),
|
||||
# ex: /adoption_notice/2/add-animal
|
||||
path("vermittlung/<int:adoption_notice_id>/add-animal", views.adoption_notice_add_animal, name="adoption-notice-add-animal"),
|
||||
|
||||
|
@ -125,6 +125,44 @@ def adoption_notice_add_animal(request, adoption_notice_id):
|
||||
return render(request, 'fellchensammlung/forms/form_add_animal_to_adoption.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def add_photo_to_animal(request, animal_id):
|
||||
animal = Animal.objects.get(id=animal_id)
|
||||
if request.method == 'POST':
|
||||
form = ImageForm(request.POST, request.FILES)
|
||||
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
animal.photos.add(instance)
|
||||
if "save-and-add-another" in request.POST:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
else:
|
||||
return redirect(reverse("animal-detail", args=[animal_id]))
|
||||
else:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def add_photo_to_adoption_notice(request, adoption_notice_id):
|
||||
adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id)
|
||||
if request.method == 'POST':
|
||||
form = ImageForm(request.POST, request.FILES)
|
||||
|
||||
if form.is_valid():
|
||||
instance = form.save()
|
||||
adoption_notice.photos.add(instance)
|
||||
if "save-and-add-another" in request.POST:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
else:
|
||||
return redirect(reverse("adoption-notice-detail", args=[adoption_notice_id]))
|
||||
else:
|
||||
form = ImageForm(in_flow=True)
|
||||
return render(request, 'fellchensammlung/forms/form-image.html', {'form': form})
|
||||
|
||||
|
||||
@login_required
|
||||
def animal_edit(request, animal_id):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user