aboutsummaryrefslogtreecommitdiff
path: root/ihatemoney/run.py
diff options
context:
space:
mode:
authorGlandos <bugs-github@antipoul.fr>2020-05-21 21:31:24 +0200
committerGitHub <noreply@github.com>2020-05-21 21:31:24 +0200
commit23ed467d37a0b1949c9cd4ef5616058d5448e030 (patch)
tree4fef765e1c10c0cb756739956659d5d9dde912d8 /ihatemoney/run.py
parentdf6ffc7d86b7334b2a3c309318cc8020cd8e781a (diff)
downloadihatemoney-mirror-23ed467d37a0b1949c9cd4ef5616058d5448e030.zip
ihatemoney-mirror-23ed467d37a0b1949c9cd4ef5616058d5448e030.tar.gz
ihatemoney-mirror-23ed467d37a0b1949c9cd4ef5616058d5448e030.tar.bz2
Replace currencyformat_nc with currency filter (#625)
Diffstat (limited to 'ihatemoney/run.py')
-rw-r--r--ihatemoney/run.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/ihatemoney/run.py b/ihatemoney/run.py
index e084e5b..15e295b 100644
--- a/ihatemoney/run.py
+++ b/ihatemoney/run.py
@@ -6,6 +6,7 @@ from flask import Flask, g, render_template, request, session
from flask_babel import Babel, format_currency
from flask_mail import Mail
from flask_migrate import Migrate, stamp, upgrade
+from jinja2 import contextfilter
from werkzeug.middleware.proxy_fix import ProxyFix
from ihatemoney import default_settings
@@ -155,7 +156,10 @@ def create_app(
# Undocumented currencyformat filter from flask_babel is forwarding to Babel format_currency
# We overwrite it to remove the currency sign ¤ when there is no currency
- def currencyformat_nc(number, currency, *args, **kwargs):
+ @contextfilter
+ def currency(context, number, currency=None, *args, **kwargs):
+ if currency is None:
+ currency = context.get("g").project.default_currency
"""
Same as flask_babel.Babel.currencyformat, but without the "no currency ¤" sign
when there is no currency.
@@ -167,7 +171,7 @@ def create_app(
**kwargs
).strip()
- app.jinja_env.filters["currencyformat_nc"] = currencyformat_nc
+ app.jinja_env.filters["currency"] = currency
@babel.localeselector
def get_locale():