diff --git a/nummi/history/templates/history/plot.html b/nummi/history/templates/history/plot.html index 23a5035..fdc756d 100644 --- a/nummi/history/templates/history/plot.html +++ b/nummi/history/templates/history/plot.html @@ -25,7 +25,7 @@ {% if date.sum_m or date.sum_p %}
{% year_url month.year account=account category=category %}
-- {% with month=previous_month %} - {% include "main/pagination_month.html" %} - {% endwith %} - {% with cur=True %} - {% include "main/pagination_month.html" %} - {% endwith %} - {% with month=next_month %} - {% include "main/pagination_month.html" %} - {% endwith %} +
{% year_url month %}
++ {% if previous_month %} + {% month_url previous_month %} + {% endif %} + {% month_url month cls="cur" %} + {% if next_month %} + {% month_url next_month %} + {% endif %}
{% endif %} {% if year %} -- {% with year=previous_year %} - {% include "main/pagination_year.html" %} - {% endwith %} - {% with cur=True %} - {% include "main/pagination_year.html" %} - {% endwith %} - {% with year=next_year %} - {% include "main/pagination_year.html" %} - {% endwith %} +
+ {% if previous_year %} + {% year_url previous_year cls="prev" %} + {% endif %} + {% year_url year cls="cur" %} + {% if next_year %} + {% year_url next_year cls="next" %} + {% endif %}
{% endif %} diff --git a/nummi/main/templates/main/pagination_month.html b/nummi/main/templates/main/pagination_month.html deleted file mode 100644 index 288427a..0000000 --- a/nummi/main/templates/main/pagination_month.html +++ /dev/null @@ -1,5 +0,0 @@ -{% load i18n %} -{% if month %} - {{ month|date:"F Y"|capfirst }} -{% endif %} diff --git a/nummi/main/templates/main/pagination_year.html b/nummi/main/templates/main/pagination_year.html deleted file mode 100644 index 5c9bd3c..0000000 --- a/nummi/main/templates/main/pagination_year.html +++ /dev/null @@ -1,5 +0,0 @@ -{% load i18n %} -{% if year %} - {{ year|date:"Y" }} -{% endif %} diff --git a/nummi/transaction/templatetags/transaction_extras.py b/nummi/transaction/templatetags/transaction_extras.py index d55b3e0..f42aafe 100644 --- a/nummi/transaction/templatetags/transaction_extras.py +++ b/nummi/transaction/templatetags/transaction_extras.py @@ -1,3 +1,5 @@ +import datetime + from django import template from django.template.defaultfilters import date from django.urls import reverse @@ -8,19 +10,21 @@ from ..utils import ac_url register = template.Library() -@register.simple_tag -def month_url(month, **kwargs): +@register.simple_tag(takes_context=True) +def month_url(context, month, cls=""): url_name, url_params = ac_url( - "transaction_month", {"year": month.year, "month": month.month}, **kwargs + "transaction_month", {"year": month.year, "month": month.month}, context ) url = reverse(url_name, kwargs=url_params) - return mark_safe(f"""{ date(month, "Y-m") }""") + return mark_safe(f"""{ date(month, "Y-m") }""") -@register.simple_tag -def year_url(year, **kwargs): - url_name, url_params = ac_url("transaction_year", {"year": year}, **kwargs) +@register.simple_tag(takes_context=True) +def year_url(context, year, cls=""): + if isinstance(year, datetime.date): + year = year.year + url_name, url_params = ac_url("transaction_year", {"year": year}, context) url = reverse(url_name, kwargs=url_params) - return mark_safe(f"""{ year }""") + return mark_safe(f"""{ year }""") diff --git a/nummi/transaction/utils.py b/nummi/transaction/utils.py index 25102e9..399dcc2 100644 --- a/nummi/transaction/utils.py +++ b/nummi/transaction/utils.py @@ -1,8 +1,8 @@ -def ac_url(url_name, url_params, account=None, category=None): - if account: +def ac_url(url_name, url_params, context): + if account := context.get("account"): url_name = "account_" + url_name url_params |= {"account": account.pk} - elif category: + elif category := context.get("category"): url_name = "category_" + url_name url_params |= {"category": category.pk}