diff --git a/CHANGELOG.md b/CHANGELOG.md index cd4914f..eae9215 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,8 @@ * Unfinished (count) * Refunded (count) * Backlog Decrease (count) +* New workflow: + * Adding Game, Edition, Purchase, and Session in a row is now much faster ### Improved * game overview: simplify playtime range display diff --git a/games/templates/add_edition.html b/games/templates/add_edition.html new file mode 100644 index 0000000..1f20ae4 --- /dev/null +++ b/games/templates/add_edition.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}{{ title }}{% endblock title %} + +{% block content %} +
+ + {% csrf_token %} + + {{ form.as_table }} + + + + + + + + +
+
+{% endblock content %} + +{% block scripts %} + {% if script_name %} + + {% endif %} +{% endblock scripts %} + \ No newline at end of file diff --git a/games/templates/add_game.html b/games/templates/add_game.html new file mode 100644 index 0000000..65b9278 --- /dev/null +++ b/games/templates/add_game.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}{{ title }}{% endblock title %} + +{% block content %} +
+ + {% csrf_token %} + + {{ form.as_table }} + + + + + + + + +
+
+{% endblock content %} + +{% block scripts %} + {% if script_name %} + + {% endif %} +{% endblock scripts %} + \ No newline at end of file diff --git a/games/templates/add_purchase.html b/games/templates/add_purchase.html new file mode 100644 index 0000000..637a888 --- /dev/null +++ b/games/templates/add_purchase.html @@ -0,0 +1,29 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}{{ title }}{% endblock title %} + +{% block content %} +
+ + {% csrf_token %} + + {{ form.as_table }} + + + + + + + + +
+
+{% endblock content %} + +{% block scripts %} + {% if script_name %} + + {% endif %} +{% endblock scripts %} + \ No newline at end of file diff --git a/games/urls.py b/games/urls.py index fbc5849..8b1abe0 100644 --- a/games/urls.py +++ b/games/urls.py @@ -13,6 +13,11 @@ urlpatterns = [ path("add-game/", views.add_game, name="add_game"), path("add-platform/", views.add_platform, name="add_platform"), path("add-session/", views.add_session, name="add_session"), + path( + "add-session-for-purchase/", + views.add_session, + name="add_session_for_purchase", + ), path( "update-session/by-session/", views.update_session, @@ -34,7 +39,17 @@ urlpatterns = [ # name="delete_session", # ), path("add-purchase/", views.add_purchase, name="add_purchase"), + path( + "add-purchase-for-edition/", + views.add_purchase, + name="add_purchase_for_edition", + ), path("add-edition/", views.add_edition, name="add_edition"), + path( + "add-edition-for-game/", + views.add_edition, + name="add_edition_for_game", + ), path("edit-edition/", views.edit_edition, name="edit_edition"), path("game//view", views.view_game, name="view_game"), path("game//edit", views.edit_game, name="edit_game"), diff --git a/games/views.py b/games/views.py index 65091ce..04af9c8 100644 --- a/games/views.py +++ b/games/views.py @@ -35,21 +35,30 @@ def stats_dropdown_year_range(request): return {"stats_dropdown_year_range": range(2018, 2024)} -def add_session(request): +def add_session(request, purchase_id=None): context = {} - initial = {} - - now = now_with_tz() - initial["timestamp_start"] = now + initial = {"timestamp_start": now_with_tz()} last = Session.objects.all().last() if last != None: initial["purchase"] = last.purchase - form = SessionForm(request.POST or None, initial=initial) - if form.is_valid(): - form.save() - return redirect("list_sessions") + if request.method == "POST": + form = SessionForm(request.POST or None, initial=initial) + if form.is_valid(): + form.save() + return redirect("list_sessions") + else: + if purchase_id: + purchase = Purchase.objects.get(id=purchase_id) + form = SessionForm( + initial={ + **initial, + "purchase": purchase, + } + ) + else: + form = SessionForm(initial=initial) context["title"] = "Add New Session" context["form"] = form @@ -397,45 +406,86 @@ def stats(request, year: int = 0): return render(request, "stats.html", context) -def add_purchase(request): +def add_purchase(request, edition_id=None): context = {} - now = datetime.now() - initial = {"date_purchased": now} - form = PurchaseForm(request.POST or None, initial=initial) - if form.is_valid(): - form.save() - return redirect("index") + initial = {"date_purchased": now_with_tz()} + + if request.method == "POST": + form = PurchaseForm(request.POST or None, initial=initial) + if form.is_valid(): + purchase = form.save() + if "submit_and_redirect" in request.POST: + return HttpResponseRedirect( + reverse( + "add_session_for_purchase", kwargs={"purchase_id": purchase.id} + ) + ) + else: + return redirect("index") + else: + if edition_id: + edition = Edition.objects.get(id=edition_id) + form = PurchaseForm( + initial={ + **initial, + "edition": edition, + "platform": edition.platform, + } + ) + else: + form = PurchaseForm(initial=initial) context["form"] = form context["title"] = "Add New Purchase" context["script_name"] = "add_purchase.js" - return render(request, "add.html", context) + return render(request, "add_purchase.html", context) def add_game(request): context = {} form = GameForm(request.POST or None) if form.is_valid(): - form.save() - return redirect("index") + game = form.save() + if "submit_and_redirect" in request.POST: + return HttpResponseRedirect( + reverse("add_edition_for_game", kwargs={"game_id": game.id}) + ) + else: + return redirect("index") context["form"] = form context["title"] = "Add New Game" context["script_name"] = "add_game.js" - return render(request, "add.html", context) + return render(request, "add_game.html", context) -def add_edition(request): +def add_edition(request, game_id=None): context = {} - form = EditionForm(request.POST or None) - if form.is_valid(): - form.save() - return redirect("index") + if request.method == "POST": + form = EditionForm(request.POST or None) + if form.is_valid(): + edition = form.save() + if "submit_and_redirect" in request.POST: + return HttpResponseRedirect( + reverse( + "add_purchase_for_edition", kwargs={"edition_id": edition.id} + ) + ) + else: + return redirect("index") + else: + if game_id: + game = Game.objects.get(id=game_id) + form = EditionForm( + initial={"game": game, "name": game.name, "sort_name": game.sort_name} + ) + else: + form = EditionForm() context["form"] = form context["title"] = "Add New Edition" context["script_name"] = "add_edition.js" - return render(request, "add.html", context) + return render(request, "add_edition.html", context) def add_platform(request):