From f02d1ab41c7f8b41192318c12c87b9990b5943ca Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO <yohann.danello@gmail.com> Date: Mon, 3 Feb 2020 15:20:37 +0100 Subject: [PATCH] Better pretty money. Closes #3 --- apps/note/templatetags/pretty_money.py | 4 ++-- templates/base.html | 4 ++-- templates/note/transactiontemplate_list.html | 17 ++++++++--------- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/apps/note/templatetags/pretty_money.py b/apps/note/templatetags/pretty_money.py index 5b7acd12..ec0a0d5b 100644 --- a/apps/note/templatetags/pretty_money.py +++ b/apps/note/templatetags/pretty_money.py @@ -3,9 +3,9 @@ from django import template def pretty_money(value): if value%100 == 0: - return str(value//100) + '€' + return "{:s}{:d} €".format("- " if value < 0 else "", abs(value) // 100) else: - return str(value//100) + '€ ' + str(value%100) + return "{:s}{:d} € {:02d}".format("- " if value < 0 else "", abs(value) // 100, abs(value) % 100) register = template.Library() diff --git a/templates/base.html b/templates/base.html index 62436772..5c857593 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,4 +1,4 @@ -{% load static i18n static %} +{% load static i18n pretty_money static %} {% comment %} SPDX-License-Identifier: GPL-3.0-or-later {% endcomment %} @@ -62,7 +62,7 @@ SPDX-License-Identifier: GPL-3.0-or-later {% if user.is_authenticated %} <li class="dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> - <i class="fa fa-user"></i> {{ user.username }} + <i class="fa fa-user"></i> {{ user.username }} ({{ user.note.balance | pretty_money }}) </a> <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink"> diff --git a/templates/note/transactiontemplate_list.html b/templates/note/transactiontemplate_list.html index 25946322..62e4d164 100644 --- a/templates/note/transactiontemplate_list.html +++ b/templates/note/transactiontemplate_list.html @@ -1,24 +1,23 @@ {% extends "base.html" %} +{% load pretty_money %} {% block content %} <table class="table"> <tr> -<td>ID</td><td>Link</td> - <td>name</td> - <td>destinataire</td> - <td>montant</td> - <td>catégorie</td> +<td>ID</td><td>Nom</td> + <td>Destinataire</td> + <td>Montant</td> + <td>Catégorie</td> </tr> {% for object in object_list %} <tr> <td>{{object.pk}}</td> - <td><a href="{{object.get_absolute_url}}">{{object}}</a></td> - <td>{{ object.name }}</td> + <td><a href="{{object.get_absolute_url}}">{{ object.name }}</a></td> <td>{{ object.destination }}</td> - <td>{{ object.amount }}</td> + <td>{{ object.amount | pretty_money }}</td> <td>{{ object.template_type }}</td> </tr> {% endfor %} </table> -<a class="btn btn-primary" href="{% url 'note:template_create' %}">New Template</a> +<a class="btn btn-primary" href="{% url 'note:template_create' %}">Créer un bouton</a> {% endblock %} -- GitLab