mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-29 01:42: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_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():
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% extends "sidebar_table_layout.html" %}
|
||||
|
||||
{%- 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 -%}
|
||||
|
||||
{% block title %} - {{ g.project.name }}{% endblock %}
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<tr receiver={{bill.receiver.id}}>
|
||||
<td>{{ bill.ower }}</td>
|
||||
<td>{{ bill.receiver }}</td>
|
||||
<td>{{ bill.amount|currencyformat_nc(g.project.default_currency) }}</td>
|
||||
<td>{{ bill.amount|currency }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
{%- endif %}
|
||||
{%- 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>
|
||||
</tr>
|
||||
{%- endfor %}
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
{% for stat in members_stats|sort(attribute='member.name') %}
|
||||
<tr>
|
||||
<td class="d-md-none">{{ stat.member.name }}</td>
|
||||
<td>{{ stat.paid|currencyformat_nc(g.project.default_currency) }}</td>
|
||||
<td>{{ stat.spent|currencyformat_nc(g.project.default_currency) }}</td>
|
||||
<td>{{ stat.paid|currency }}</td>
|
||||
<td>{{ stat.spent|currency }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
@ -28,7 +28,7 @@
|
|||
{% for month in months %}
|
||||
<tr>
|
||||
<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>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
|
Loading…
Reference in a new issue