Refactor pagination for month/year
This commit is contained in:
parent
35b26f2d10
commit
2ba21fbd10
7 changed files with 51 additions and 44 deletions
|
@ -25,7 +25,7 @@
|
||||||
{% if date.sum_m or date.sum_p %}
|
{% if date.sum_m or date.sum_p %}
|
||||||
<tr {% if not date.month.month|divisibleby:"2" %}class="even"{% endif %}>
|
<tr {% if not date.month.month|divisibleby:"2" %}class="even"{% endif %}>
|
||||||
<td class="icon">{% up_down_icon date.sum %}</td>
|
<td class="icon">{% up_down_icon date.sum %}</td>
|
||||||
<th class="date" scope="row">{% month_url date.month account=account category=category %}</th>
|
<th class="date" scope="row">{% month_url date.month %}</th>
|
||||||
<td class="value">{{ date.sum_m|pmrvalue }}</td>
|
<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 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>
|
<td class="bar p">{% plot_bar date.sum date.sum_p history.max.pm %}</td>
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
{% regroup history.data by month.year as years_list %}
|
{% regroup history.data by month.year as years_list %}
|
||||||
{% for y, year in years_list reversed %}
|
{% for y, year in years_list reversed %}
|
||||||
<tr>
|
<tr>
|
||||||
<th class="date" scope="row">{% year_url y account=account category=category %}</th>
|
<th class="date" scope="row">{% year_url y %}</th>
|
||||||
{% for m in year %}
|
{% for m in year %}
|
||||||
{% if forloop.parentloop.last and forloop.first %}
|
{% if forloop.parentloop.last and forloop.first %}
|
||||||
{% empty_calendar_cells_start m.month.month %}
|
{% empty_calendar_cells_start m.month.month %}
|
||||||
|
|
|
@ -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) {
|
@media (width < 1024px) {
|
||||||
|
|
|
@ -8,29 +8,25 @@
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if month %}
|
{% if month %}
|
||||||
<p class="pagination">{% year_url month.year account=account category=category %}</p>
|
<p class="pagination">{% year_url month %}</p>
|
||||||
<p class="pagination">
|
<p class="pagination n3">
|
||||||
{% with month=previous_month %}
|
{% if previous_month %}
|
||||||
{% include "main/pagination_month.html" %}
|
{% month_url previous_month %}
|
||||||
{% endwith %}
|
{% endif %}
|
||||||
{% with cur=True %}
|
{% month_url month cls="cur" %}
|
||||||
{% include "main/pagination_month.html" %}
|
{% if next_month %}
|
||||||
{% endwith %}
|
{% month_url next_month %}
|
||||||
{% with month=next_month %}
|
{% endif %}
|
||||||
{% include "main/pagination_month.html" %}
|
|
||||||
{% endwith %}
|
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if year %}
|
{% if year %}
|
||||||
<p class="pagination">
|
<p class="pagination n3">
|
||||||
{% with year=previous_year %}
|
{% if previous_year %}
|
||||||
{% include "main/pagination_year.html" %}
|
{% year_url previous_year cls="prev" %}
|
||||||
{% endwith %}
|
{% endif %}
|
||||||
{% with cur=True %}
|
{% year_url year cls="cur" %}
|
||||||
{% include "main/pagination_year.html" %}
|
{% if next_year %}
|
||||||
{% endwith %}
|
{% year_url next_year cls="next" %}
|
||||||
{% with year=next_year %}
|
{% endif %}
|
||||||
{% include "main/pagination_year.html" %}
|
|
||||||
{% endwith %}
|
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
{% 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 %}
|
|
|
@ -1,5 +0,0 @@
|
||||||
{% 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,3 +1,5 @@
|
||||||
|
import datetime
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.template.defaultfilters import date
|
from django.template.defaultfilters import date
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
@ -8,19 +10,21 @@ from ..utils import ac_url
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag(takes_context=True)
|
||||||
def month_url(month, **kwargs):
|
def month_url(context, month, cls=""):
|
||||||
url_name, url_params = ac_url(
|
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)
|
url = reverse(url_name, kwargs=url_params)
|
||||||
return mark_safe(f"""<a href="{url}">{ date(month, "Y-m") }</a>""")
|
return mark_safe(f"""<a class="{cls}" href="{url}">{ date(month, "Y-m") }</a>""")
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag
|
@register.simple_tag(takes_context=True)
|
||||||
def year_url(year, **kwargs):
|
def year_url(context, year, cls=""):
|
||||||
url_name, url_params = ac_url("transaction_year", {"year": year}, **kwargs)
|
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)
|
url = reverse(url_name, kwargs=url_params)
|
||||||
return mark_safe(f"""<a href="{url}">{ year }</a>""")
|
return mark_safe(f"""<a class="{cls}" href="{url}">{ year }</a>""")
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
def ac_url(url_name, url_params, account=None, category=None):
|
def ac_url(url_name, url_params, context):
|
||||||
if account:
|
if account := context.get("account"):
|
||||||
url_name = "account_" + url_name
|
url_name = "account_" + url_name
|
||||||
url_params |= {"account": account.pk}
|
url_params |= {"account": account.pk}
|
||||||
elif category:
|
elif category := context.get("category"):
|
||||||
url_name = "category_" + url_name
|
url_name = "category_" + url_name
|
||||||
url_params |= {"category": category.pk}
|
url_params |= {"category": category.pk}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue