Fix number filters

This commit is contained in:
Edgar P. Burkhart 2022-05-24 18:10:01 +02:00
parent 408e605c7b
commit d2d27caf41
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
8 changed files with 36 additions and 19 deletions

View file

@ -21,7 +21,7 @@
} }
.chart .value { .chart .value {
padding: 0 var(--gap); padding: 0 var(--gap);
font-feature-settings: "tnum", "ss01"; font-feature-settings: var(--num);
text-align: right; text-align: right;
} }
.chart .bar { .chart .bar {
@ -53,7 +53,7 @@
top: .5rem; top: .5rem;
line-height: 1.5rem; line-height: 1.5rem;
height: 1.5rem; height: 1.5rem;
font-feature-settings: "tnum", "ss01"; font-feature-settings: var(--num);
} }
.chart .right .bar span {left: 0} .chart .right .bar span {left: 0}
.chart .left .bar span {right: 0} .chart .left .bar span {right: 0}

View file

@ -33,6 +33,8 @@
--green-1: var(--theme-1); --green-1: var(--theme-1);
--radius: 2px; --radius: 2px;
--num: "tnum", "ss01", "case";
} }
body { body {

View file

@ -34,7 +34,7 @@
text-align: right; text-align: right;
} }
.table > div > .num { .table > div > .num {
font-feature-settings: "tnum", "ss01"; font-feature-settings: var(--num);
} }
.table > div > span.value { .table > div > span.value {
filter: brightness(95%); filter: brightness(95%);

View file

@ -31,13 +31,13 @@
<span class="date num center"> <span class="date num center">
<a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a> <a href="{% url 'snapshot' snap.id %}">{{ snap.date|date:"Y-m-d" }}</a>
</span> </span>
<span class="value num right">{% value snap.value %}</span> <span class="value num right">{{ snap.value|value }}</span>
<span class="diff num right"> <span class="diff num right">
{% pmvalue snap.diff %} {{ snap.diff|pmvalue }}
</span> </span>
{% with sum=snap.sum %} {% with sum=snap.sum %}
<span class="sum num right"> <span class="sum num right">
{% pmvalue sum %} {{ sum|pmvalue }}
</span> </span>
<span class="valid center"> <span class="valid center">
{% if snap.previous is not None %} {% if snap.previous is not None %}

View file

@ -46,7 +46,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="value left"> <div class="value left">
{% pmvalue cat.sum_m %} {{ cat.sum_m|pmvalue }}
</div> </div>
<div class="left"> <div class="left">
<div <div
@ -59,7 +59,7 @@
class="bar tot" class="bar tot"
style="width:{% widthratio cat.sum cat_lim_m 100 %}%" style="width:{% widthratio cat.sum cat_lim_m 100 %}%"
title="{{ cat.sum }}"> title="{{ cat.sum }}">
{% pmvalue cat.sum %} <span>{{ cat.sum|pmvalue }}</span>
</div> </div>
{% endif %} {% endif %}
</div> </div>
@ -74,18 +74,18 @@
class="bar tot" class="bar tot"
style="width:{% widthratio cat.sum cat_lim 100 %}%" style="width:{% widthratio cat.sum cat_lim 100 %}%"
title="{{ cat.sum }}"> title="{{ cat.sum }}">
{% pmvalue cat.sum %} <span>{{ cat.sum|pmvalue }}</span>
</div> </div>
{% endif %} {% endif %}
</div> </div>
<div class="value right"> <div class="value right">
{% pmvalue cat.sum_p %} {{ cat.sum_p|pmvalue }}
</div> </div>
{% endfor %} {% endfor %}
</div> </div>
{% if snapshot.transactions %} {% if snapshot.transactions %}
<h2>Transactions ({% pmvalue sum %} / {% pmvalue snapshot.diff %})</h2> <h2>Transactions ({{ sum|pmvalue }} / {{ snapshot.diff|pmvalue }})</h2>
{% transaction_table snapshot.transactions %} {% transaction_table snapshot.transactions %}
{% endif %} {% endif %}

View file

@ -13,7 +13,7 @@
<div class="transaction {% cycle 'w' 'g' %}"> <div class="transaction {% cycle 'w' 'g' %}">
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span> <span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span> <span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
<span class="value num right">{% pmvalue trans.value %}</span> <span class="value num right">{{ trans.value|pmvalue }}</span>
<span class="trader text center">{{ trans.trader|default_if_none:"" }}</span> <span class="trader text center">{{ trans.trader|default_if_none:"" }}</span>
<span class="category text center"> <span class="category text center">
{% if trans.category %} {% if trans.category %}

View file

@ -1,7 +1,7 @@
{% spaceless %} {% spaceless %}
<span> <span>
{% block "value" %} {% block "value" %}
{{ value|floatformat:"2g" }} € {{ value }} €
{% endblock %} {% endblock %}
</span> </span>
{% endspaceless %} {% endspaceless %}

View file

@ -1,17 +1,32 @@
from django import template from django import template
from django.template.defaultfilters import stringfilter from django.template.defaultfilters import stringfilter
from django.utils import formats
from django.utils.safestring import mark_safe
register = template.Library() register = template.Library()
@register.inclusion_tag("main/tag/value.html") @register.filter
def value(value): def value(val, pm=False):
return {"value": value} if not val:
return mark_safe("&ndash;")
_prefix = ""
_suffix = "&nbsp;€"
_val = formats.number_format(val, 2, use_l10n=True)
if val > 0:
if pm:
_prefix += "&plus;&nbsp;"
else:
_val = _val[1:]
_prefix += "&minus;&nbsp;"
return mark_safe(f"{_prefix}{_val}{_suffix}")
@register.inclusion_tag("main/tag/pmvalue.html") @register.filter
def pmvalue(value): def pmvalue(val):
return {"value": value} return value(val, True)
@register.inclusion_tag("main/tag/transaction_table.html") @register.inclusion_tag("main/tag/transaction_table.html")