Compare commits

..

2 commits

7 changed files with 51 additions and 15 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

View file

@ -20,3 +20,16 @@
{% endwith %}
</p>
{% endif %}
{% if year %}
<p class="pagination">
{% 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 %}
</p>
{% endif %}

View file

@ -1,5 +1,5 @@
{% load i18n %}
{% if month %}
<a {% if cur %}class="cur"{% endif %}
href="{% if account %}{% url "account_transaction_month" account.id month|date:"Y" month|date:"m" %}{% elif category %}{% url "category_transaction_month" category.id month|date:"Y" month|date:"m" %}{% else %}{% url "transaction_month" month|date:"Y" month|date:"m" %}{% endif %}">{{ month|date:"F Y"|capfirst }}</a>
href="{% if account %}{% url "account_transaction_month" account.id month.year month.month %}{% elif category %}{% url "category_transaction_month" category.id month.year month.month %}{% else %}{% url "transaction_month" month.year month.month %}{% endif %}">{{ month|date:"F Y"|capfirst }}</a>
{% endif %}

View file

@ -0,0 +1,5 @@
{% load i18n %}
{% if year %}
<a {% if cur %}class="cur"{% endif %}
href="{% if account %}{% url "account_transaction_year" account.id year.year %}{% elif category %}{% url "category_transaction_year" category.id year.year %}{% else %}{% url "transaction_year" year.year %}{% endif %}">{{ year|date:"Y" }}</a>
{% endif %}