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 %} {% up_down_icon date.sum %} - {% month_url date.month account=account category=category %} + {% month_url date.month %} {{ date.sum_m|pmrvalue }} {% plot_bar date.sum date.sum_m history.max.pm %} {% plot_bar date.sum date.sum_p history.max.pm %} @@ -53,7 +53,7 @@ {% regroup history.data by month.year as years_list %} {% for y, year in years_list reversed %} - {% year_url y account=account category=category %} + {% year_url y %} {% for m in year %} {% if forloop.parentloop.last and forloop.first %} {% empty_calendar_cells_start m.month.month %} diff --git a/nummi/main/static/main/css/main.css b/nummi/main/static/main/css/main.css index d48a265..3fa85f8 100644 --- a/nummi/main/static/main/css/main.css +++ b/nummi/main/static/main/css/main.css @@ -163,6 +163,23 @@ footer { } } } + + &.n3 { + display: grid; + grid-template-columns: repeat(3, 1fr); + width: max-content; + margin: auto; + + .prev { + grid-column: 1; + } + .cur { + grid-column: 2; + } + .next { + grid-column: 3; + } + } } @media (width < 1024px) { diff --git a/nummi/main/templates/main/pagination.html b/nummi/main/templates/main/pagination.html index 54e9e12..0370ae0 100644 --- a/nummi/main/templates/main/pagination.html +++ b/nummi/main/templates/main/pagination.html @@ -8,29 +8,25 @@

{% endif %} {% if month %} -

{% 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}