Fix year urls on account pages

This commit is contained in:
Edgar P. Burkhart 2024-01-02 12:13:57 +01:00
parent 60f84fe20d
commit 2f32c2b80f
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
4 changed files with 32 additions and 14 deletions

View File

@ -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(
"<account>/history/<int:year>",
TransactionYearView.as_view(),
name="account_transaction_year",
),
path(
"<account>/history/<int:year>/<int:month>",
TransactionMonthView.as_view(),

View File

@ -52,9 +52,7 @@
{% regroup history.data by month.year as years_list %}
{% for y, year in years_list reversed %}
<tr>
<th>
<a href="{% url "transaction_year" y %}">{{ y }}</a>
</th>
<th class="date" scope="row">{% year_url y account=account category=category %}</th>
{% for m in year %}
{% if forloop.parentloop.last and forloop.first %}
{% empty_calendar_cells_start m.month.month %}

View File

@ -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"""<a href="{url}">{ date(month, "Y-m") }</a>""")
@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"""<a href="{url}">{ year }</a>""")
@register.simple_tag
def plot_bar(s, sum_pm, s_max):
_res = ""

View File

@ -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