From 0f080f53163744b2aaad22e33a673dda7de38664 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Kucharczyk?= Date: Mon, 29 Apr 2024 16:20:44 +0200 Subject: [PATCH] Allow deleting purchasesp --- CHANGELOG.md | 1 + games/templates/add_purchase.html | 6 ++++++ games/urls.py | 5 +++++ games/views.py | 6 ++++++ 4 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 323848b..cc0ef33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Render notes as Markdown * Require login by default * Add stats for dropped purchases, monthly playtimes +* Allow deleting purchases ## Improved * mark refunded purchases red on game overview diff --git a/games/templates/add_purchase.html b/games/templates/add_purchase.html index cab7f60..dbf1afc 100644 --- a/games/templates/add_purchase.html +++ b/games/templates/add_purchase.html @@ -22,6 +22,12 @@ value="Submit & Create Session" /> + + + + Delete + + {% endblock content %} diff --git a/games/urls.py b/games/urls.py index 87d6dde..846c10d 100644 --- a/games/urls.py +++ b/games/urls.py @@ -47,6 +47,11 @@ urlpatterns = [ # views.delete_session, # name="delete_session", # ), + path( + "purchase//delete", + views.delete_purchase, + name="delete_purchase", + ), path("add-purchase/", views.add_purchase, name="add_purchase"), path( "add-purchase-for-edition/", diff --git a/games/views.py b/games/views.py index 2f9581c..4940ad8 100644 --- a/games/views.py +++ b/games/views.py @@ -129,6 +129,7 @@ def edit_purchase(request, purchase_id=None): return redirect("list_sessions") context["title"] = "Edit Purchase" context["form"] = form + context["purchase_id"] = purchase_id context["script_name"] = "add_purchase.js" return render(request, "add_purchase.html", context) @@ -590,6 +591,11 @@ def stats(request, year: int = 0): request.session["return_path"] = request.path return render(request, "stats.html", context) +@login_required +def delete_purchase(request, purchase_id=None): + purchase = get_object_or_404(Purchase, id=purchase_id) + purchase.delete() + return redirect("list_sessions") @login_required def add_purchase(request, edition_id=None):