1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/ihatemoney_ynh.git synced 2024-09-03 19:26:15 +02:00

Added a template filter not to show zero decimals on user weights

This commit is contained in:
Jocelyn Delande 2015-08-20 13:45:53 +02:00
parent b57df5cd36
commit 85abc0b1fc
3 changed files with 20 additions and 1 deletions

View file

@ -9,6 +9,8 @@ from raven.contrib.flask import Sentry
from web import main, db, mail
from api import api
from utils import PrefixedWSGI
from utils import minimal_round
app = Flask(__name__)
@ -37,6 +39,9 @@ configure()
app.register_blueprint(main)
app.register_blueprint(api)
# custom jinja2 filters
app.jinja_env.filters['minimal_round'] = minimal_round
# db
db.init_app(app)
db.app = app

View file

@ -63,7 +63,7 @@
{% set balance = g.project.balance %}
{% for member in g.project.members | sort(attribute='name') if member.activated or balance[member.id] != 0 %}
<tr id="bal-member-{{ member.id }}" action={% if member.activated %}delete{% else %}reactivate{% endif %}>
<td class="balance-name">{{ member.name }} <span class="light">(x{{ member.weight }})</span></td>
<td class="balance-name">{{ member.name }} <span class="light">(x{{ member.weight|minimal_round(1) }})</span></td>
{% if member.activated %}
<td>
<form class="action delete" action="{{ url_for(".remove_member", member_id=member.id) }}" method="POST">

View file

@ -1,6 +1,7 @@
import re
import inspect
from jinja2 import filters
from flask import redirect
from werkzeug.routing import HTTPException, RoutingException
@ -63,3 +64,16 @@ class PrefixedWSGI(object):
if scheme:
environ['wsgi.url_scheme'] = scheme
return self.wsgi_app(environ, start_response)
def minimal_round(*args, **kw):
""" Jinja2 filter: rounds, but display only non-zero decimals
from http://stackoverflow.com/questions/28458524/
"""
# Use the original round filter, to deal with the extra arguments
res = filters.do_round(*args, **kw)
# Test if the result is equivalent to an integer and
# return depending on it
ires = int(res)
return (res if res != ires else ires)