From 786d7c213061356864baa5074288a4fb1cff018e Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Thu, 2 Jan 2025 14:19:06 +0100 Subject: [PATCH] Use templatetags for statement_table --- nummi/account/templates/account/account_detail.html | 12 +++++++----- nummi/account/views.py | 3 ++- nummi/main/templates/main/index.html | 4 ++-- .../templates/statement/statement_list.html | 10 +++++----- nummi/statement/templatetags/statement_extras.py | 7 +++++++ 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/nummi/account/templates/account/account_detail.html b/nummi/account/templates/account/account_detail.html index 183a2f1..fcd9321 100644 --- a/nummi/account/templates/account/account_detail.html +++ b/nummi/account/templates/account/account_detail.html @@ -1,12 +1,14 @@ {% extends "main/base.html" %} -{% load main_extras %} +{% load main_extras statement_extras %} {% load i18n %} -{% block title %}{{ object }} – {{ block.super }}{% endblock %} +{% block title %} + {{ object }} – {{ block.super }} +{% endblock title %} {% block link %} {{ block.super }} {% css "main/css/table.css" %} {% css "main/css/plot.css" %} -{% endblock %} +{% endblock link %} {% block body %}

{{ object.icon|remix }}{{ object }}

@@ -14,7 +16,7 @@

{% translate "Statements" %}

- {% include "statement/statement_table.html" %} + {% statement_table statements statements_url=statements_url new_statement_url=new_statement_url %}
{% if history %}
@@ -22,4 +24,4 @@ {% include "history/plot.html" %}
{% endif %} -{% endblock %} +{% endblock body %} diff --git a/nummi/account/views.py b/nummi/account/views.py index c3cbc36..92066cd 100644 --- a/nummi/account/views.py +++ b/nummi/account/views.py @@ -9,6 +9,7 @@ from main.views import ( NummiUpdateView, ) from statement.views import StatementListView +from transaction.models import Transaction from transaction.views import TransactionListView from .forms import AccountForm @@ -51,7 +52,7 @@ class AccountDetailView(NummiDetailView): "new_statement", kwargs={"account": account.pk} ), "statements": _statements[:_max], - "history": history(account.transaction_set), + "history": history(Transaction.objects.filter(statement__account=account)), } diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index 3b82d2f..d601937 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -1,6 +1,6 @@ {% extends "main/base.html" %} {% load static %} -{% load main_extras account_extras %} +{% load main_extras account_extras statement_extras %} {% load i18n %} {% block link %} {{ block.super }} @@ -16,7 +16,7 @@

{% translate "Statements" %}

- {% include "statement/statement_table.html" %} + {% statement_table statements statements_url=statements_url %}
diff --git a/nummi/statement/templates/statement/statement_list.html b/nummi/statement/templates/statement/statement_list.html index 9d3ea04..6970a63 100644 --- a/nummi/statement/templates/statement/statement_list.html +++ b/nummi/statement/templates/statement/statement_list.html @@ -1,12 +1,12 @@ {% extends "main/list.html" %} -{% load i18n %} +{% load i18n statement_extras %} {% block name %} {% translate "Statements" %} -{% endblock %} +{% endblock name %} {% block h2 %} {% translate "Statements" %} -{% endblock %} +{% endblock h2 %} {% block table %} {% url "new_statement" as new_statement_url %} - {% include "statement/statement_table.html" %} -{% endblock %} + {% statement_table statements new_statement_url=new_statement_url %} +{% endblock table %} diff --git a/nummi/statement/templatetags/statement_extras.py b/nummi/statement/templatetags/statement_extras.py index a8631d1..54eef80 100644 --- a/nummi/statement/templatetags/statement_extras.py +++ b/nummi/statement/templatetags/statement_extras.py @@ -12,3 +12,10 @@ def check(s, diff): return remix("check", "green") else: return remix("close", "red") + + +@register.inclusion_tag("statement/statement_table.html") +def statement_table(statements, **kwargs): + return kwargs | { + "statements": statements, + }