From a456468a71813ef72e12d54a2bb050b1e639d5d3 Mon Sep 17 00:00:00 2001 From: PA Date: Wed, 14 Aug 2019 16:02:43 +0200 Subject: [PATCH] Pretty print feature Prints the money of each user perfectly --- apps/note/templatetags/__init__.py | 0 apps/note/templatetags/pretty_money.py | 12 ++++++++++++ templates/member/profile_detail.html | 4 ++-- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 apps/note/templatetags/__init__.py create mode 100644 apps/note/templatetags/pretty_money.py diff --git a/apps/note/templatetags/__init__.py b/apps/note/templatetags/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/apps/note/templatetags/pretty_money.py b/apps/note/templatetags/pretty_money.py new file mode 100644 index 00000000..5b7acd12 --- /dev/null +++ b/apps/note/templatetags/pretty_money.py @@ -0,0 +1,12 @@ +from django import template + + +def pretty_money(value): + if value%100 == 0: + return str(value//100) + '€' + else: + return str(value//100) + '€ ' + str(value%100) + + +register = template.Library() +register.filter('pretty_money', pretty_money) diff --git a/templates/member/profile_detail.html b/templates/member/profile_detail.html index ea2f0f07..11f50f65 100644 --- a/templates/member/profile_detail.html +++ b/templates/member/profile_detail.html @@ -1,5 +1,5 @@ {% extends "base.html" %} -{% load i18n static %} +{% load i18n static pretty_money %} {% block content %}

Compte n° {{ object.pk }}

@@ -20,7 +20,7 @@
{% trans 'address'|capfirst %}
{{ object.address }}
{% trans 'balance'|capfirst %}
-
{{ object.user.note.balance }}
+
{{ object.user.note.balance | pretty_money }}
{% trans 'Change password' %}