Add year link on month view
This commit is contained in:
parent
57279b1cda
commit
35b26f2d10
8 changed files with 57 additions and 56 deletions
|
@ -1,5 +1,6 @@
|
|||
{% load main_extras %}
|
||||
{% load history_extras %}
|
||||
{% load transaction_extras %}
|
||||
{% load i18n %}
|
||||
<div class="history plot">
|
||||
<table class="full-width">
|
||||
|
|
|
@ -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"""<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 = ""
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -19,21 +19,23 @@
|
|||
<h2>
|
||||
{% block h2 %}{% endblock %}
|
||||
</h2>
|
||||
{% if account %}
|
||||
<p>
|
||||
<a class="big-link" href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if category %}
|
||||
<p>
|
||||
<a class="big-link" href="{{ category.get_absolute_url }}">{{ category.icon|remix }}{{ category }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if search %}
|
||||
<p>
|
||||
<a href="{% url "search" %}">{% translate "Search" %}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% block backlinks %}
|
||||
{% if account %}
|
||||
<p>
|
||||
<a class="big-link" href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if category %}
|
||||
<p>
|
||||
<a class="big-link" href="{{ category.get_absolute_url }}">{{ category.icon|remix }}{{ category }}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if search %}
|
||||
<p>
|
||||
<a href="{% url "search" %}">{% translate "Search" %}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
{% include "main/pagination.html" %}
|
||||
{% block table %}{% endblock %}
|
||||
{% include "main/pagination.html" %}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% load i18n %}
|
||||
{% load i18n transaction_extras %}
|
||||
{% if page_obj %}
|
||||
<p class="pagination">
|
||||
{% for page in paginator.page_range %}
|
||||
|
@ -8,6 +8,7 @@
|
|||
</p>
|
||||
{% endif %}
|
||||
{% if month %}
|
||||
<p class="pagination">{% year_url month.year account=account category=category %}</p>
|
||||
<p class="pagination">
|
||||
{% with month=previous_month %}
|
||||
{% include "main/pagination_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" %}
|
||||
|
|
26
nummi/transaction/templatetags/transaction_extras.py
Normal file
26
nummi/transaction/templatetags/transaction_extras.py
Normal file
|
@ -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"""<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>""")
|
9
nummi/transaction/utils.py
Normal file
9
nummi/transaction/utils.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue