From b589199ca639c9b18f01c46ec206c9b08f2eff77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 10 Sep 2024 14:46:50 +0200 Subject: [PATCH] drop purchase from list --- games/templates/cotton/icon/eject.html | 8 ++++++++ games/urls.py | 5 +++++ games/views/purchase.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 games/templates/cotton/icon/eject.html diff --git a/games/templates/cotton/icon/eject.html b/games/templates/cotton/icon/eject.html new file mode 100644 index 0000000..fac0832 --- /dev/null +++ b/games/templates/cotton/icon/eject.html @@ -0,0 +1,8 @@ + + + + diff --git a/games/urls.py b/games/urls.py index 97565cd..fab22c6 100644 --- a/games/urls.py +++ b/games/urls.py @@ -44,6 +44,11 @@ urlpatterns = [ purchase.edit_purchase, name="edit_purchase", ), + path( + "purchase//drop", + purchase.drop_purchase, + name="drop_purchase", + ), path( "purchase//delete", purchase.delete_purchase, diff --git a/games/views/purchase.py b/games/views/purchase.py index a353227..7209d79 100644 --- a/games/views/purchase.py +++ b/games/views/purchase.py @@ -103,6 +103,15 @@ def list_purchases(request: HttpRequest) -> HttpResponse: "cotton/button_group.html", { "buttons": [ + { + "href": reverse( + "drop_purchase", args=[purchase.pk] + ), + "slot": Icon("eject"), + "title": "Mark as dropped", + } + if not purchase.date_dropped + else {}, { "href": reverse( "edit_purchase", args=[purchase.pk] @@ -189,6 +198,14 @@ def delete_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: return redirect("list_sessions") +@login_required +def drop_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: + purchase = get_object_or_404(Purchase, id=purchase_id) + purchase.date_dropped = timezone.now() + purchase.save() + return redirect("list_sessions") + + def related_purchase_by_edition(request: HttpRequest) -> HttpResponse: edition_id = request.GET.get("edition") if not edition_id: