Skip to content
Snippets Groups Projects
Commit f318dd62 authored by Tobias Mieves's avatar Tobias Mieves :sparkles:
Browse files

feat: Add delete confirm view

Also refactor the delete view as class based view.
The wish template now has a readonly mode
parent e7fa1489
No related branches found
No related tags found
No related merge requests found
......@@ -14,3 +14,4 @@ services:
- ./wishlist-db/:/app/db/
environment:
- DEBUG=True
- SECRET_KEY=Test
{% extends 'wishlist/wishlist-base.html' %}
{% block content %}
<form action="" method="post" class="m-auto w-3/4">
{% csrf_token %}
<div class="card bg-base-100 shadow-xl">
<div class="card-body">
<h2 class="card-title text-2xl">Wunsch wirklich löschen?</h2>
{% include "wishlist/wish_template.html" with wish=wish readonly=True %}
<div class="card-actions justify-end mt-4">
<input type="submit" class="btn btn-secondary" value="Cancel" name="cancel" />
<input type="submit" class="btn btn-error" value="Confirm deletion" name="confirm_delete" />
</div>
</div>
</div>
</form>
{% endblock %}
......@@ -47,6 +47,7 @@
rel="noopener noreferrer">Link</a>
</div>
{% endif %}
{% if not readonly %}
<div class="card-actions">
{% if wish.owner == user %}
<a class="btn btn-sm"
......@@ -64,13 +65,14 @@
</a>
{% endif %}
</div>
{% endif %}
{% if wish.dependent_wishes.all %}
<div class="collapse collapse-arrow {% if wish.reserved_by.all|length > 0 %}collapse-open{% endif %}">
<input type="checkbox" />
<div class="collapse-title text-xl font-medium">Abhängige Wünsche</div>
<div class="collapse-content">
{% for dep_wish in wish.dependent_wishes.all %}
{% include "wishlist/wish_template.html" with wish=dep_wish %}
{% include "wishlist/wish_template.html" with wish=dep_wish readonly=readonly %}
{% endfor %}
</div>
</div>
......
......@@ -8,7 +8,7 @@ urlpatterns = [
path(
"wish/add/<int:list_owner>", views.CreateWishView.as_view(), name="createWish"
),
path("wish/delete/<int:wish_id>", views.deleteWishView, name="deleteWish"),
path("wish/delete/<int:pk>", views.DeleteWishView.as_view(), name="deleteWish"),
path(
"wish/favorite/<int:wish_id>", views.toggleFavoriteView, name="toggleFavorite"
),
......
......@@ -7,7 +7,7 @@ from django.forms import modelform_factory
from django.http import HttpResponseRedirect, HttpRequest
from django.shortcuts import render, get_object_or_404
from django.urls import reverse
from django.views.generic import CreateView, UpdateView, ListView
from django.views.generic import CreateView, UpdateView, ListView, DeleteView
from wishlist.mixins import IsWishOwnerMixin
from wishlist.models import Wish, Reservation, Group
......@@ -114,6 +114,13 @@ class CreateWishView(LoginRequiredMixin, CreateView):
return context
class DeleteWishView(LoginRequiredMixin, IsWishOwnerMixin, DeleteView):
model = Wish
def get_success_url(self):
return reverse("wishList", kwargs={"list_owner": self.request.GET["list_owner"]})
@login_required
def deleteWishView(request, wish_id):
wish = get_object_or_404(Wish, pk=wish_id)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment