mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 21:11:49 +02:00
make a custom filter for currency, based on currencyformat
this just strip currency sign, and leading/trailing non-breaking spaces
This commit is contained in:
parent
1cfe3c1148
commit
bb8e10ceef
2 changed files with 18 additions and 3 deletions
|
@ -3,7 +3,7 @@ import os.path
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
from flask import Flask, g, render_template, request, session
|
from flask import Flask, g, render_template, request, session
|
||||||
from flask_babel import Babel
|
from flask_babel import Babel, format_currency
|
||||||
from flask_mail import Mail
|
from flask_mail import Mail
|
||||||
from flask_migrate import Migrate, stamp, upgrade
|
from flask_migrate import Migrate, stamp, upgrade
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
@ -153,6 +153,22 @@ def create_app(
|
||||||
# Translations
|
# Translations
|
||||||
babel = Babel(app)
|
babel = Babel(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):
|
||||||
|
"""
|
||||||
|
Same as flask_babel.Babel.currencyformat, but without the "no currency ¤" sign
|
||||||
|
when there is no currency.
|
||||||
|
"""
|
||||||
|
return format_currency(
|
||||||
|
number,
|
||||||
|
currency if currency != CurrencyConverter.no_currency else "",
|
||||||
|
*args,
|
||||||
|
**kwargs
|
||||||
|
).strip()
|
||||||
|
|
||||||
|
app.jinja_env.filters["currencyformat_nc"] = currencyformat_nc
|
||||||
|
|
||||||
@babel.localeselector
|
@babel.localeselector
|
||||||
def get_locale():
|
def get_locale():
|
||||||
# get the lang from the session if defined, fallback on the browser "accept
|
# get the lang from the session if defined, fallback on the browser "accept
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
{% extends "sidebar_table_layout.html" %}
|
{% extends "sidebar_table_layout.html" %}
|
||||||
|
|
||||||
{%- macro bill_amount(bill, currency=bill.original_currency, amount=bill.amount) %}
|
{%- macro bill_amount(bill, currency=bill.original_currency, amount=bill.amount) %}
|
||||||
{# Undocumented currencyformat filter from flask_babel is forwarding to Babel format_currency #}
|
{{ amount|currencyformat_nc(currency) }} ({{ _("%(amount)s each", amount=bill.pay_each_default(amount)|currencyformat_nc(currency)) }})
|
||||||
{{ amount|currencyformat(currency if currency != 'XXX' else '') }} ({{ _("%(amount)s each", amount=bill.pay_each_default(amount)|currencyformat(currency if currency != 'XXX' else '')) }})
|
|
||||||
{% endmacro -%}
|
{% endmacro -%}
|
||||||
|
|
||||||
{% block title %} - {{ g.project.name }}{% endblock %}
|
{% block title %} - {{ g.project.name }}{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue