Compare commits
No commits in common. "2ba21fbd10cce71942bbe5579505d6c9c5686d01" and "57279b1cda6abcc6ba7a3bfc64b2993f721dd596" have entirely different histories.
2ba21fbd10
...
57279b1cda
11 changed files with 88 additions and 96 deletions
|
@ -1,6 +1,5 @@
|
|||
{% load main_extras %}
|
||||
{% load history_extras %}
|
||||
{% load transaction_extras %}
|
||||
{% load i18n %}
|
||||
<div class="history plot">
|
||||
<table class="full-width">
|
||||
|
@ -25,7 +24,7 @@
|
|||
{% if date.sum_m or date.sum_p %}
|
||||
<tr {% if not date.month.month|divisibleby:"2" %}class="even"{% endif %}>
|
||||
<td class="icon">{% up_down_icon date.sum %}</td>
|
||||
<th class="date" scope="row">{% month_url date.month %}</th>
|
||||
<th class="date" scope="row">{% month_url date.month account=account category=category %}</th>
|
||||
<td class="value">{{ date.sum_m|pmrvalue }}</td>
|
||||
<td class="bar m">{% plot_bar date.sum date.sum_m history.max.pm %}</td>
|
||||
<td class="bar p">{% plot_bar date.sum date.sum_p history.max.pm %}</td>
|
||||
|
@ -53,7 +52,7 @@
|
|||
{% regroup history.data by month.year as years_list %}
|
||||
{% for y, year in years_list reversed %}
|
||||
<tr>
|
||||
<th class="date" scope="row">{% year_url y %}</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 %}
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
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()
|
||||
|
||||
|
||||
|
@ -35,6 +39,24 @@ 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,9 +1,14 @@
|
|||
import datetime
|
||||
|
||||
from django.db.models import Max, Min, Q, Sum
|
||||
from django.db.models import Func, 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
|
||||
|
@ -45,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
|
||||
|
|
|
@ -163,23 +163,6 @@ 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) {
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
<h2>
|
||||
{% block h2 %}{% endblock %}
|
||||
</h2>
|
||||
{% block backlinks %}
|
||||
{% if account %}
|
||||
<p>
|
||||
<a class="big-link" href="{{ account.get_absolute_url }}">{{ account.icon|remix }}{{ account }}</a>
|
||||
|
@ -35,7 +34,6 @@
|
|||
<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 transaction_extras %}
|
||||
{% load i18n %}
|
||||
{% if page_obj %}
|
||||
<p class="pagination">
|
||||
{% for page in paginator.page_range %}
|
||||
|
@ -8,25 +8,28 @@
|
|||
</p>
|
||||
{% endif %}
|
||||
{% if month %}
|
||||
<p class="pagination">{% year_url month %}</p>
|
||||
<p class="pagination n3">
|
||||
{% if previous_month %}
|
||||
{% month_url previous_month %}
|
||||
{% endif %}
|
||||
{% month_url month cls="cur" %}
|
||||
{% if next_month %}
|
||||
{% month_url next_month %}
|
||||
{% endif %}
|
||||
<p class="pagination">
|
||||
{% 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 %}
|
||||
</p>
|
||||
{% endif %}
|
||||
{% if year %}
|
||||
<p class="pagination n3">
|
||||
{% 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 %}
|
||||
<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 %}
|
||||
|
|
5
nummi/main/templates/main/pagination_month.html
Normal file
5
nummi/main/templates/main/pagination_month.html
Normal file
|
@ -0,0 +1,5 @@
|
|||
{% load i18n %}
|
||||
{% if month %}
|
||||
<a {% if cur %}class="cur"{% endif %}
|
||||
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 %}
|
5
nummi/main/templates/main/pagination_year.html
Normal file
5
nummi/main/templates/main/pagination_year.html
Normal 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 %}
|
|
@ -1,5 +1,5 @@
|
|||
{% extends "transaction/transaction_list.html" %}
|
||||
{% load i18n main_extras transaction_extras static category %}
|
||||
{% load i18n main_extras static category %}
|
||||
{% block link %}
|
||||
{{ block.super }}
|
||||
{% css "main/css/plot.css" %}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
import datetime
|
||||
|
||||
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(takes_context=True)
|
||||
def month_url(context, month, cls=""):
|
||||
url_name, url_params = ac_url(
|
||||
"transaction_month", {"year": month.year, "month": month.month}, context
|
||||
)
|
||||
|
||||
url = reverse(url_name, kwargs=url_params)
|
||||
return mark_safe(f"""<a class="{cls}" href="{url}">{ date(month, "Y-m") }</a>""")
|
||||
|
||||
|
||||
@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"""<a class="{cls}" href="{url}">{ year }</a>""")
|
|
@ -1,9 +0,0 @@
|
|||
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 := context.get("category"):
|
||||
url_name = "category_" + url_name
|
||||
url_params |= {"category": category.pk}
|
||||
|
||||
return url_name, url_params
|
Loading…
Reference in a new issue