From 9e66e1aaced58325f66dd7595e12a18effabbf45 Mon Sep 17 00:00:00 2001 From: Timotheus Pokorra Date: Fri, 5 Mar 2021 20:36:02 +0100 Subject: [PATCH] also format the exchange rates properly related to #20 --- apps/transactions/templates/show.html | 7 ++++--- apps/transactions/templatetags/__init__.py | 0 apps/transactions/templatetags/filter.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 apps/transactions/templatetags/__init__.py create mode 100644 apps/transactions/templatetags/filter.py diff --git a/apps/transactions/templates/show.html b/apps/transactions/templates/show.html index 686c339..4438022 100644 --- a/apps/transactions/templates/show.html +++ b/apps/transactions/templates/show.html @@ -1,5 +1,6 @@ {% extends 'base.html' %} {% load humanize %} +{% load filter %} {% block content %}
@@ -22,13 +23,13 @@ {{ transaction.date_valid }} {{ transaction.amount_before_fee|floatformat:3 }} {{ transaction.crypto_currency }} - {{ transaction.amount|floatformat:2 }} {{ transaction.fiat_currency }} + {{ transaction.amount|formatcurrency }} {{ transaction.fiat_currency }} {% if transaction.amount < 0 %} - {{ transaction.exchange_rate|floatformat:0 }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }} + {{ transaction.exchange_rate|formatcurrency }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }} {% endif %} {% if transaction.amount > 0 %} - {{ transaction.exchange_rate|floatformat:0 }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }} + {{ transaction.exchange_rate|formatcurrency }} {{ transaction.crypto_currency }}/{{ transaction.fiat_currency }} {% endif %} diff --git a/apps/transactions/templatetags/__init__.py b/apps/transactions/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/transactions/templatetags/filter.py b/apps/transactions/templatetags/filter.py new file mode 100644 index 0000000..e556ed3 --- /dev/null +++ b/apps/transactions/templatetags/filter.py @@ -0,0 +1,10 @@ +from django import template + +register = template.Library() + +@register.filter +def formatcurrency(value): + if value > 100: + return "%0.0f" % (value,) + return "%0.2f" % (value,) +