feat: Add option to delete animal
This commit is contained in:
@@ -3,13 +3,13 @@
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{{ form.name.data }}</h1>
|
||||
<h1>{{ animal }}</h1>
|
||||
<form method="post" enctype="multipart/form-data">
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form }}
|
||||
<input class="button is-primary" type="submit" value="{% translate "Speichern" %}">
|
||||
|
||||
<a class="button is-danger">{% translate "Löschen" %}</a>
|
||||
<a class="button is-danger" href="{% url 'animal-delete' animal_id=animal.pk %}">{% translate "Löschen" %}</a>
|
||||
</form>
|
||||
{% endblock %}
|
@@ -0,0 +1,17 @@
|
||||
{% extends "fellchensammlung/base_bulma.html" %}
|
||||
{% load i18n %}
|
||||
{% load widget_tweaks %}
|
||||
|
||||
{% block title %}
|
||||
<title>Löschen von {{ animal }} bestätigen</title>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1 class="title is-1">Löschen von {{ animal }} bestätigen</h1>
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
<a class="button" href="{% url 'animal-edit' animal_id=animal.pk %}">{% translate "Zurück (nicht löschen)" %}</a>
|
||||
<input class="button is-danger" type="submit" name="delete" value={% translate "Löschen" %}>
|
||||
</form>
|
||||
{% endblock %}
|
@@ -24,6 +24,8 @@ 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/delete
|
||||
path("tier/<int:animal_id>/delete", views.animal_delete, name="animal-delete"),
|
||||
# ex: /animal/5/add-photo
|
||||
path("tier/<int:animal_id>/add-photo", views.add_photo_to_animal_bulma, name="animal-add-photo"),
|
||||
# ex: /adoption_notice/7/
|
||||
|
@@ -389,7 +389,30 @@ def animal_edit(request, animal_id):
|
||||
return redirect(reverse("adoption-notice-detail", args=[animal.adoption_notice.pk], ))
|
||||
else:
|
||||
form = AnimalForm(instance=animal)
|
||||
return render(request, 'fellchensammlung/forms/form-animal.html', context={"form": form})
|
||||
return render(request, 'fellchensammlung/forms/form-animal.html',
|
||||
context={"form": form, "animal": animal})
|
||||
|
||||
|
||||
@login_required
|
||||
def animal_delete(request, animal_id):
|
||||
"""
|
||||
Shows a conformation page from which a user can delete an animal or go back to the adoption notice.
|
||||
"""
|
||||
animal = Animal.objects.get(pk=animal_id)
|
||||
# Only users that are mods or owners of the animal are allowed to edit it
|
||||
fail_if_user_not_owner_or_trust_level(request.user, animal)
|
||||
if request.method == 'POST':
|
||||
if "delete" in request.POST:
|
||||
# First delete related images, then animal
|
||||
images = animal.get_photos()
|
||||
for image in images:
|
||||
image.delete()
|
||||
animal.delete()
|
||||
"""Log"""
|
||||
Log.objects.create(user=request.user, action="delete_animal",
|
||||
text=f"{request.user} hat Tier {animal.pk} gelöscht")
|
||||
return redirect(reverse("adoption-notice-detail", args=[animal.adoption_notice.pk], ))
|
||||
return render(request, 'fellchensammlung/forms/form-delete-animal.html', context={"animal": animal})
|
||||
|
||||
|
||||
def about_bulma(request):
|
||||
|
Reference in New Issue
Block a user