Improve calendar table

This commit is contained in:
Edgar P. Burkhart 2024-12-30 17:29:42 +01:00
parent a3e598acb6
commit 28ac9c8ef7
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
3 changed files with 19 additions and 4 deletions

View file

@ -3,13 +3,14 @@
{% load transaction_extras %} {% load transaction_extras %}
{% load i18n %} {% load i18n %}
<div class="calendar"> <div class="calendar">
<table class="full-width"> <table>
<thead> <thead>
<tr> <tr>
{% if not year %} {% if not year %}
<th scope="col">{% translate "Year" %}</th> <th scope="col">{% translate "Year" %}</th>
{% endif %} {% endif %}
{% calendar_head %} {% calendar_head %}
<th scope="col">{% translate "Total" %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -24,16 +25,17 @@
{% empty_calendar_cells_start m.month.month %} {% empty_calendar_cells_start m.month.month %}
{% endif %} {% endif %}
{% if m %} {% if m %}
<td class="{% if m.sum > 0 %}p{% else %}m{% endif %}" <td class="month {% if m.sum > 0 %}p{% else %}m{% endif %}"
style="--opacity: {% calendar_opacity m.sum history.max.sum %}" style="--opacity: {% calendar_opacity m.sum history.max.sum %}"
title="{{ m.sum|pmrvalue }}">{% up_down_icon m.sum %}</td> title="{{ m.sum|pmrvalue }}">{% up_down_icon m.sum %}</td>
{% else %} {% else %}
<td></td> <td class="month"></td>
{% endif %} {% endif %}
{% if forloop.parentloop.first and forloop.last %} {% if forloop.parentloop.first and forloop.last %}
{% empty_calendar_cells_end m.month.month %} {% empty_calendar_cells_end m.month.month %}
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<td class="total">{{ y_data|sum_year|pmrvalue }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View file

@ -60,3 +60,8 @@ def calendar_head():
th = (f"""<th>{month:02d}</th>""" for month in months) th = (f"""<th>{month:02d}</th>""" for month in months)
return mark_safe("".join(th)) return mark_safe("".join(th))
@register.filter
def sum_year(y_data):
return sum(y["sum"] for y in y_data)

View file

@ -95,13 +95,16 @@ table.full-width col.bar {
border-top: none; border-top: none;
} }
td { td.month {
text-align: center; text-align: center;
background-color: color-mix( background-color: color-mix(
in hsl, in hsl,
var(--td-bg, var(--bg)) var(--opacity), var(--td-bg, var(--bg)) var(--opacity),
var(--bg) var(--bg)
); );
padding: 0;
width: 4rem;
height: 4rem;
&.p { &.p {
--td-bg: var(--green); --td-bg: var(--green);
} }
@ -109,6 +112,11 @@ table.full-width col.bar {
--td-bg: var(--red); --td-bg: var(--red);
} }
} }
td.total {
text-align: right;
font-weight: 650;
font-feature-settings: var(--num);
}
} }
} }
} }