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

View file

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

View file

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

View file

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

View file

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

View file

@ -13,7 +13,7 @@
<div class="transaction {% cycle 'w' 'g' %}">
<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="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="category text center">
{% if trans.category %}

View file

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

View file

@ -1,17 +1,32 @@
from django import template
from django.template.defaultfilters import stringfilter
from django.utils import formats
from django.utils.safestring import mark_safe
register = template.Library()
@register.inclusion_tag("main/tag/value.html")
def value(value):
return {"value": value}
@register.filter
def value(val, pm=False):
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")
def pmvalue(value):
return {"value": value}
@register.filter
def pmvalue(val):
return value(val, True)
@register.inclusion_tag("main/tag/transaction_table.html")