diff options
| author | Jocelyn Delande <jocelyn@crapouillou.net> | 2015-08-20 13:45:53 +0200 |
|---|---|---|
| committer | Jocelyn Delande <jocelyn@crapouillou.net> | 2016-06-15 10:20:37 +0200 |
| commit | 85abc0b1fcbee6549425fad87b3cdd55669672d2 (patch) | |
| tree | 1cc49e4bd911339073df8fbf47ea61bde44dc476 /budget/utils.py | |
| parent | b57df5cd368eca946e5699237a954d37fb342b07 (diff) | |
| download | ihatemoney-mirror-85abc0b1fcbee6549425fad87b3cdd55669672d2.zip ihatemoney-mirror-85abc0b1fcbee6549425fad87b3cdd55669672d2.tar.gz ihatemoney-mirror-85abc0b1fcbee6549425fad87b3cdd55669672d2.tar.bz2 | |
Added a template filter not to show zero decimals on user weights
Diffstat (limited to 'budget/utils.py')
| -rw-r--r-- | budget/utils.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/budget/utils.py b/budget/utils.py index 7717aaa..c849af0 100644 --- a/budget/utils.py +++ b/budget/utils.py @@ -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) |
