From 2f32c2b80f279d4c2c0060d10090e22e0d950094 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Tue, 2 Jan 2024 12:13:57 +0100 Subject: [PATCH] Fix year urls on account pages --- nummi/account/urls.py | 7 +++++- nummi/history/templates/history/plot.html | 4 +--- nummi/history/templatetags/history_extras.py | 24 ++++++++++++-------- nummi/history/utils.py | 11 +++++++++ 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/nummi/account/urls.py b/nummi/account/urls.py index e15f4d4..d9b8c14 100644 --- a/nummi/account/urls.py +++ b/nummi/account/urls.py @@ -1,6 +1,6 @@ from django.urls import path from statement.views import StatementCreateView -from transaction.views import TransactionMonthView +from transaction.views import TransactionMonthView, TransactionYearView from . import views @@ -27,6 +27,11 @@ urlpatterns = [ views.AccountDeleteView.as_view(), name="del_account", ), + path( + "/history/", + TransactionYearView.as_view(), + name="account_transaction_year", + ), path( "/history//", TransactionMonthView.as_view(), diff --git a/nummi/history/templates/history/plot.html b/nummi/history/templates/history/plot.html index 6231995..954c3ce 100644 --- a/nummi/history/templates/history/plot.html +++ b/nummi/history/templates/history/plot.html @@ -52,9 +52,7 @@ {% regroup history.data by month.year as years_list %} {% for y, year in years_list reversed %} - - {{ y }} - + {% year_url y account=account category=category %} {% for m in year %} {% if forloop.parentloop.last and forloop.first %} {% empty_calendar_cells_start m.month.month %} diff --git a/nummi/history/templatetags/history_extras.py b/nummi/history/templatetags/history_extras.py index 1efb7ec..3991f8f 100644 --- a/nummi/history/templatetags/history_extras.py +++ b/nummi/history/templatetags/history_extras.py @@ -6,6 +6,8 @@ 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() @@ -38,21 +40,23 @@ def up_down_icon(val): @register.simple_tag -def month_url(month, account=None, category=None): - url_name = "transaction_month" - url_params = {"year": month.year, "month": month.month} - - if account: - url_name = "account_" + url_name - url_params |= {"account": account.pk} - elif category: - url_name = "category_" + url_name - url_params |= {"category": category.pk} +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 423d34e..530a44f 100644 --- a/nummi/history/utils.py +++ b/nummi/history/utils.py @@ -50,3 +50,14 @@ 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