From 7f6584ecf78edb053d21c11bcc8f52a22582ae13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Tue, 10 Sep 2024 15:04:18 +0200 Subject: [PATCH] finish purchase from list --- games/templates/cotton/icon/checkmark.html | 8 ++++++++ games/urls.py | 5 +++++ games/views/purchase.py | 17 +++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 games/templates/cotton/icon/checkmark.html diff --git a/games/templates/cotton/icon/checkmark.html b/games/templates/cotton/icon/checkmark.html new file mode 100644 index 0000000..5dc1e9c --- /dev/null +++ b/games/templates/cotton/icon/checkmark.html @@ -0,0 +1,8 @@ + + + + diff --git a/games/urls.py b/games/urls.py index 99c0367..edd5def 100644 --- a/games/urls.py +++ b/games/urls.py @@ -54,6 +54,11 @@ urlpatterns = [ purchase.delete_purchase, name="delete_purchase", ), + path( + "purchase//finish", + purchase.finish_purchase, + name="finish_purchase", + ), path( "purchase/list", purchase.list_purchases, diff --git a/games/views/purchase.py b/games/views/purchase.py index 0ebddf3..d7c06d7 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( + "finish_purchase", args=[purchase.pk] + ), + "slot": Icon("checkmark"), + "title": "Mark as finished", + } + if not purchase.date_finished + else {}, { "href": reverse( "drop_purchase", args=[purchase.pk] @@ -223,6 +232,14 @@ def refund_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: return redirect("list_purchases") +@login_required +def finish_purchase(request: HttpRequest, purchase_id: int) -> HttpResponse: + purchase = get_object_or_404(Purchase, id=purchase_id) + purchase.date_finished = timezone.now() + purchase.save() + return redirect("list_purchases") + + def related_purchase_by_edition(request: HttpRequest) -> HttpResponse: edition_id = request.GET.get("edition") if not edition_id: