From a10e798c8ca46c77c61d8262e0ef2441896ab08a Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Wed, 25 May 2022 08:14:50 +0200 Subject: [PATCH] Add templating for form buttons --- nummi/main/templates/main/category.html | 6 +----- nummi/main/templates/main/snapshot.html | 6 +----- nummi/main/templates/main/tag/form_buttons.html | 11 +++++++++++ nummi/main/templates/main/transaction.html | 7 ++----- nummi/main/templatetags/main_extras.py | 10 ++++++++++ nummi/main/views.py | 5 ++++- 6 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 nummi/main/templates/main/tag/form_buttons.html diff --git a/nummi/main/templates/main/category.html b/nummi/main/templates/main/category.html index 0a7bd04..f9ee58c 100644 --- a/nummi/main/templates/main/category.html +++ b/nummi/main/templates/main/category.html @@ -14,11 +14,7 @@
{% csrf_token %} {{ form }} -
- - - -
+ {% form_buttons category %}
{% if transactions %} diff --git a/nummi/main/templates/main/snapshot.html b/nummi/main/templates/main/snapshot.html index 4850ddd..4bfb42d 100644 --- a/nummi/main/templates/main/snapshot.html +++ b/nummi/main/templates/main/snapshot.html @@ -25,11 +25,7 @@
{% csrf_token %} {{ form }} -
- - - -
+ {% form_buttons snapshot %}
{% if categories %} diff --git a/nummi/main/templates/main/tag/form_buttons.html b/nummi/main/templates/main/tag/form_buttons.html new file mode 100644 index 0000000..f6abe8b --- /dev/null +++ b/nummi/main/templates/main/tag/form_buttons.html @@ -0,0 +1,11 @@ +
+ {% if not adding %} + + {% endif %} + + +
diff --git a/nummi/main/templates/main/transaction.html b/nummi/main/templates/main/transaction.html index 0b693ab..1b648e0 100644 --- a/nummi/main/templates/main/transaction.html +++ b/nummi/main/templates/main/transaction.html @@ -1,5 +1,6 @@ {% extends "main/base.html" %} {% load static %} +{% load main_extras %} {% block link %} {{ block.super }} @@ -14,11 +15,7 @@ {% csrf_token %} {{ form }} -
- - - -
+ {% form_buttons transaction %} {% endspaceless %} diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index 9af8f92..e816fd5 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -32,3 +32,13 @@ def pmvalue(val): @register.inclusion_tag("main/tag/transaction_table.html") def transaction_table(transactions): return {"transactions": transactions} + + +@register.inclusion_tag("main/tag/form_buttons.html") +def form_buttons(instance): + return { + "instance": instance, + "adding": instance._state.adding, + "name": instance.__class__.__name__, + "del_url": f"del_{instance.__class__.__name__.lower()}" + } diff --git a/nummi/main/views.py b/nummi/main/views.py index c239e65..f26fee3 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -128,6 +128,7 @@ def category(request, uuid=None): "category": _category, "form": _form, "transactions": Transaction.objects.filter(category=_category), + "adding": _category._state.adding, }, ) @@ -165,7 +166,9 @@ def snapshot(request, uuid=None): if _snapshot.transactions: context["categories"] = ( - _snapshot.transactions.values("category", "category__name", "category__icon") + _snapshot.transactions.values( + "category", "category__name", "category__icon" + ) .annotate( sum=models.Sum("value"), sum_m=models.Sum("value", filter=models.Q(value__lt=0)),