From 35b26f2d1032e160aa3acb5e174a85c7ca7c6e1c Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 2 Jan 2024 14:35:39 +0100 Subject: [PATCH] Add year link on month view --- nummi/history/templates/history/plot.html | 1 + nummi/history/templatetags/history_extras.py | 22 ------------- nummi/history/utils.py | 18 +---------- nummi/main/templates/main/list.html | 32 ++++++++++--------- nummi/main/templates/main/pagination.html | 3 +- .../transaction_archive_month.html | 2 +- .../templatetags/transaction_extras.py | 26 +++++++++++++++ nummi/transaction/utils.py | 9 ++++++ 8 files changed, 57 insertions(+), 56 deletions(-) create mode 100644 nummi/transaction/templatetags/transaction_extras.py create mode 100644 nummi/transaction/utils.py diff --git a/nummi/history/templates/history/plot.html b/nummi/history/templates/history/plot.html index 954c3ce..23a5035 100644 --- a/nummi/history/templates/history/plot.html +++ b/nummi/history/templates/history/plot.html @@ -1,5 +1,6 @@ {% load main_extras %} {% load history_extras %} +{% load transaction_extras %} {% load i18n %}
diff --git a/nummi/history/templatetags/history_extras.py b/nummi/history/templatetags/history_extras.py index 3991f8f..48a8aaf 100644 --- a/nummi/history/templatetags/history_extras.py +++ b/nummi/history/templatetags/history_extras.py @@ -1,13 +1,9 @@ import math from django import template -from django.template.defaultfilters import date -from django.urls import reverse from django.utils.safestring import mark_safe from main.templatetags.main_extras import pmrvalue, remix -from ..utils import ac_url - register = template.Library() @@ -39,24 +35,6 @@ def up_down_icon(val): return remix("arrow-down-s", "red") -@register.simple_tag -def month_url(month, **kwargs): - url_name, url_params = ac_url( - "transaction_month", {"year": month.year, "month": month.month}, **kwargs - ) - - url = reverse(url_name, kwargs=url_params) - 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) - - url = reverse(url_name, kwargs=url_params) - return mark_safe(f"""{ year }""") - - @register.simple_tag def plot_bar(s, sum_pm, s_max): _res = "" diff --git a/nummi/history/utils.py b/nummi/history/utils.py index 530a44f..320c10a 100644 --- a/nummi/history/utils.py +++ b/nummi/history/utils.py @@ -1,14 +1,9 @@ import datetime -from django.db.models import Func, Max, Min, Q, Sum +from django.db.models import Max, Min, Q, Sum from django.db.models.functions import Abs, TruncMonth -class GenerateMonth(Func): - function = "generate_series" - template = "%(function)s(%(expressions)s, '1 month')::date" - - def history(transaction_set): if not transaction_set.exists(): return None @@ -50,14 +45,3 @@ def history(transaction_set): "sum": _history.aggregate(max=Max(Abs("sum")))["max"], }, } - - -def ac_url(url_name, url_params, account=None, category=None): - if account: - url_name = "account_" + url_name - url_params |= {"account": account.pk} - elif category: - url_name = "category_" + url_name - url_params |= {"category": category.pk} - - return url_name, url_params diff --git a/nummi/main/templates/main/list.html b/nummi/main/templates/main/list.html index ee3050e..cd223b7 100644 --- a/nummi/main/templates/main/list.html +++ b/nummi/main/templates/main/list.html @@ -19,21 +19,23 @@

{% block h2 %}{% endblock %}

- {% if account %} -

- {{ account.icon|remix }}{{ account }} -

- {% endif %} - {% if category %} -

- {{ category.icon|remix }}{{ category }} -

- {% endif %} - {% if search %} -

- {% translate "Search" %} -

- {% endif %} + {% block backlinks %} + {% if account %} +

+ {{ account.icon|remix }}{{ account }} +

+ {% endif %} + {% if category %} +

+ {{ category.icon|remix }}{{ category }} +

+ {% endif %} + {% if search %} +

+ {% translate "Search" %} +

+ {% endif %} + {% endblock %} {% include "main/pagination.html" %} {% block table %}{% endblock %} {% include "main/pagination.html" %} diff --git a/nummi/main/templates/main/pagination.html b/nummi/main/templates/main/pagination.html index 7f32ea2..54e9e12 100644 --- a/nummi/main/templates/main/pagination.html +++ b/nummi/main/templates/main/pagination.html @@ -1,4 +1,4 @@ -{% load i18n %} +{% load i18n transaction_extras %} {% if page_obj %}

{% for page in paginator.page_range %} @@ -8,6 +8,7 @@

{% endif %} {% if month %} +

{% year_url month.year account=account category=category %}

{% with month=previous_month %} {% include "main/pagination_month.html" %} diff --git a/nummi/transaction/templates/transaction/transaction_archive_month.html b/nummi/transaction/templates/transaction/transaction_archive_month.html index 3b71c4e..4ecaa53 100644 --- a/nummi/transaction/templates/transaction/transaction_archive_month.html +++ b/nummi/transaction/templates/transaction/transaction_archive_month.html @@ -1,5 +1,5 @@ {% extends "transaction/transaction_list.html" %} -{% load i18n main_extras static category %} +{% load i18n main_extras transaction_extras static category %} {% block link %} {{ block.super }} {% css "main/css/plot.css" %} diff --git a/nummi/transaction/templatetags/transaction_extras.py b/nummi/transaction/templatetags/transaction_extras.py new file mode 100644 index 0000000..d55b3e0 --- /dev/null +++ b/nummi/transaction/templatetags/transaction_extras.py @@ -0,0 +1,26 @@ +from django import template +from django.template.defaultfilters import date +from django.urls import reverse +from django.utils.safestring import mark_safe + +from ..utils import ac_url + +register = template.Library() + + +@register.simple_tag +def month_url(month, **kwargs): + url_name, url_params = ac_url( + "transaction_month", {"year": month.year, "month": month.month}, **kwargs + ) + + url = reverse(url_name, kwargs=url_params) + 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) + + url = reverse(url_name, kwargs=url_params) + return mark_safe(f"""{ year }""") diff --git a/nummi/transaction/utils.py b/nummi/transaction/utils.py new file mode 100644 index 0000000..25102e9 --- /dev/null +++ b/nummi/transaction/utils.py @@ -0,0 +1,9 @@ +def ac_url(url_name, url_params, account=None, category=None): + if account: + url_name = "account_" + url_name + url_params |= {"account": account.pk} + elif category: + url_name = "category_" + url_name + url_params |= {"category": category.pk} + + return url_name, url_params