Better pretty money. Closes #3

This commit is contained in:
Yohann D'ANELLO 2020-02-03 15:20:37 +01:00
parent 24017dafaf
commit f02d1ab41c
3 changed files with 12 additions and 13 deletions

View File

@ -3,9 +3,9 @@ from django import template
def pretty_money(value): def pretty_money(value):
if value%100 == 0: if value%100 == 0:
return str(value//100) + '' return "{:s}{:d}".format("- " if value < 0 else "", abs(value) // 100)
else: 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() register = template.Library()

View File

@ -1,4 +1,4 @@
{% load static i18n static %} {% load static i18n pretty_money static %}
{% comment %} {% comment %}
SPDX-License-Identifier: GPL-3.0-or-later SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %} {% endcomment %}
@ -62,7 +62,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li class="dropdown"> <li class="dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> <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> </a>
<div class="dropdown-menu dropdown-menu-right" <div class="dropdown-menu dropdown-menu-right"
aria-labelledby="navbarDropdownMenuLink"> aria-labelledby="navbarDropdownMenuLink">

View File

@ -1,24 +1,23 @@
{% extends "base.html" %} {% extends "base.html" %}
{% load pretty_money %}
{% block content %} {% block content %}
<table class="table"> <table class="table">
<tr> <tr>
<td>ID</td><td>Link</td> <td>ID</td><td>Nom</td>
<td>name</td> <td>Destinataire</td>
<td>destinataire</td> <td>Montant</td>
<td>montant</td> <td>Catégorie</td>
<td>catégorie</td>
</tr> </tr>
{% for object in object_list %} {% for object in object_list %}
<tr> <tr>
<td>{{object.pk}}</td> <td>{{object.pk}}</td>
<td><a href="{{object.get_absolute_url}}">{{object}}</a></td> <td><a href="{{object.get_absolute_url}}">{{ object.name }}</a></td>
<td>{{ object.name }}</td>
<td>{{ object.destination }}</td> <td>{{ object.destination }}</td>
<td>{{ object.amount }}</td> <td>{{ object.amount | pretty_money }}</td>
<td>{{ object.template_type }}</td> <td>{{ object.template_type }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </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 %} {% endblock %}