diff --git a/nummi/main/static/main/css/chart.css b/nummi/main/static/main/css/chart.css index dfa4ff4..fdf6ec2 100644 --- a/nummi/main/static/main/css/chart.css +++ b/nummi/main/static/main/css/chart.css @@ -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} diff --git a/nummi/main/static/main/css/main.css b/nummi/main/static/main/css/main.css index 9675162..1cb4894 100644 --- a/nummi/main/static/main/css/main.css +++ b/nummi/main/static/main/css/main.css @@ -33,6 +33,8 @@ --green-1: var(--theme-1); --radius: 2px; + + --num: "tnum", "ss01", "case"; } body { diff --git a/nummi/main/static/main/css/table.css b/nummi/main/static/main/css/table.css index 84ebe3c..8a064c2 100644 --- a/nummi/main/static/main/css/table.css +++ b/nummi/main/static/main/css/table.css @@ -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%); diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index ba97a3a..06a0205 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -31,13 +31,13 @@ {{ snap.date|date:"Y-m-d" }} - {% value snap.value %} + {{ snap.value|value }} - {% pmvalue snap.diff %} + {{ snap.diff|pmvalue }} {% with sum=snap.sum %} - {% pmvalue sum %} + {{ sum|pmvalue }} {% if snap.previous is not None %} diff --git a/nummi/main/templates/main/snapshot.html b/nummi/main/templates/main/snapshot.html index 37df888..0318343 100644 --- a/nummi/main/templates/main/snapshot.html +++ b/nummi/main/templates/main/snapshot.html @@ -46,7 +46,7 @@ {% endif %}
- {% pmvalue cat.sum_m %} + {{ cat.sum_m|pmvalue }}
- {% pmvalue cat.sum %} + {{ cat.sum|pmvalue }}
{% endif %}
@@ -74,18 +74,18 @@ class="bar tot" style="width:{% widthratio cat.sum cat_lim 100 %}%" title="{{ cat.sum }}"> - {% pmvalue cat.sum %} + {{ cat.sum|pmvalue }} {% endif %}
- {% pmvalue cat.sum_p %} + {{ cat.sum_p|pmvalue }}
{% endfor %} {% if snapshot.transactions %} -

Transactions ({% pmvalue sum %} / {% pmvalue snapshot.diff %})

+

Transactions ({{ sum|pmvalue }} / {{ snapshot.diff|pmvalue }})

{% transaction_table snapshot.transactions %} {% endif %} diff --git a/nummi/main/templates/main/tag/transaction_table.html b/nummi/main/templates/main/tag/transaction_table.html index 2ab25d1..9dd3cf5 100644 --- a/nummi/main/templates/main/tag/transaction_table.html +++ b/nummi/main/templates/main/tag/transaction_table.html @@ -13,7 +13,7 @@
{{ trans.date|date:"Y-m-d" }} {{ trans.name }} - {% pmvalue trans.value %} + {{ trans.value|pmvalue }} {{ trans.trader|default_if_none:"–" }} {% if trans.category %} diff --git a/nummi/main/templates/main/tag/value.html b/nummi/main/templates/main/tag/value.html index d004f9a..9ba2cf7 100644 --- a/nummi/main/templates/main/tag/value.html +++ b/nummi/main/templates/main/tag/value.html @@ -1,7 +1,7 @@ {% spaceless %} {% block "value" %} - {{ value|floatformat:"2g" }} € + {{ value }} € {% endblock %} {% endspaceless %} diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index 4f911e6..924f4cc 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -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("–") + _prefix = "" + _suffix = " €" + _val = formats.number_format(val, 2, use_l10n=True) + + if val > 0: + if pm: + _prefix += "+ " + else: + _val = _val[1:] + _prefix += "− " + + 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")