mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 17:52:37 +02:00
Replace currencyformat_nc with currency filter (#625)
This commit is contained in:
parent
df6ffc7d86
commit
23ed467d37
5 changed files with 12 additions and 8 deletions
|
@ -6,6 +6,7 @@ from flask import Flask, g, render_template, request, session
|
||||||
from flask_babel import Babel, format_currency
|
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 jinja2 import contextfilter
|
||||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||||
|
|
||||||
from ihatemoney import default_settings
|
from ihatemoney import default_settings
|
||||||
|
@ -155,7 +156,10 @@ def create_app(
|
||||||
|
|
||||||
# Undocumented currencyformat filter from flask_babel is forwarding to Babel format_currency
|
# 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
|
# 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
|
Same as flask_babel.Babel.currencyformat, but without the "no currency ¤" sign
|
||||||
when there is no currency.
|
when there is no currency.
|
||||||
|
@ -167,7 +171,7 @@ def create_app(
|
||||||
**kwargs
|
**kwargs
|
||||||
).strip()
|
).strip()
|
||||||
|
|
||||||
app.jinja_env.filters["currencyformat_nc"] = currencyformat_nc
|
app.jinja_env.filters["currency"] = currency
|
||||||
|
|
||||||
@babel.localeselector
|
@babel.localeselector
|
||||||
def get_locale():
|
def get_locale():
|
||||||
|
|
|
@ -1,7 +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) %}
|
||||||
{{ amount|currencyformat_nc(currency) }} ({{ _("%(amount)s each", amount=bill.pay_each_default(amount)|currencyformat_nc(currency)) }})
|
{{ amount|currency(currency) }} ({{ _("%(amount)s each", amount=bill.pay_each_default(amount)|currency(currency)) }})
|
||||||
{% endmacro -%}
|
{% endmacro -%}
|
||||||
|
|
||||||
{% block title %} - {{ g.project.name }}{% endblock %}
|
{% block title %} - {{ g.project.name }}{% endblock %}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<tr receiver={{bill.receiver.id}}>
|
<tr receiver={{bill.receiver.id}}>
|
||||||
<td>{{ bill.ower }}</td>
|
<td>{{ bill.ower }}</td>
|
||||||
<td>{{ bill.receiver }}</td>
|
<td>{{ bill.receiver }}</td>
|
||||||
<td>{{ bill.amount|currencyformat_nc(g.project.default_currency) }}</td>
|
<td>{{ bill.amount|currency }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
<td class="balance-value {% if balance[member.id]|round(2) > 0 %}positive{% elif balance[member.id]|round(2) < 0 %}negative{% endif %}">
|
<td class="balance-value {% if balance[member.id]|round(2) > 0 %}positive{% elif balance[member.id]|round(2) < 0 %}negative{% endif %}">
|
||||||
{% if balance[member.id] | round(2) > 0 %}+{% endif %}{{ balance[member.id]|currencyformat_nc(g.project.default_currency) }}
|
{% if balance[member.id] | round(2) > 0 %}+{% endif %}{{ balance[member.id]|currency }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
{% for stat in members_stats|sort(attribute='member.name') %}
|
{% for stat in members_stats|sort(attribute='member.name') %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="d-md-none">{{ stat.member.name }}</td>
|
<td class="d-md-none">{{ stat.member.name }}</td>
|
||||||
<td>{{ stat.paid|currencyformat_nc(g.project.default_currency) }}</td>
|
<td>{{ stat.paid|currency }}</td>
|
||||||
<td>{{ stat.spent|currencyformat_nc(g.project.default_currency) }}</td>
|
<td>{{ stat.spent|currency }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
{% for month in months %}
|
{% for month in months %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ _(month.strftime("%B")) }} {{ month.year }}</td>
|
<td>{{ _(month.strftime("%B")) }} {{ month.year }}</td>
|
||||||
<td>{{ monthly_stats[month.year][month.month]|currencyformat_nc(g.project.default_currency) }}</td>
|
<td>{{ monthly_stats[month.year][month.month]|currency }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
Loading…
Reference in a new issue