Don't crash when rendering None price

This commit is contained in:
Midgard 2022-05-11 02:43:08 +02:00
parent 7b16a3b6c5
commit b5202a9de6
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 6 additions and 3 deletions

View file

@ -19,7 +19,7 @@ from login import init_login
from markupsafe import Markup
from models import db
from models.anonymous_user import AnonymouseUser
from utils import euro_string, price_range_string
from utils import euro_string, price_range_string, ignore_none
from zeus import init_oauth
@ -151,6 +151,7 @@ def add_template_filters(app: Flask) -> None:
app.template_filter("price_range")(price_range_string)
app.template_filter("any")(any)
app.template_filter("all")(all)
app.template_filter("ignore_none")(ignore_none)
def create_app():

View file

@ -281,7 +281,7 @@
{{ "disabled" if not order.can_modify_payment(current_user.id) }}>
<span class="price" style="{{ 'opacity: 0.5' if paid }}">
{{ order_items | map(attribute="price") | sum | euro }}
{{ order_items | map(attribute="price") | ignore_none | sum | euro }}
</span>
{% if paid %}<span class="glyphicon glyphicon-ok" style="opacity: 0.5"></span>{% endif %}

View file

@ -4,10 +4,12 @@ import re
from typing import Iterable, Optional
def euro_string(value: int, unit="") -> str:
def euro_string(value: Optional[int], unit="") -> str:
"""
Convert cents to string formatted euro
"""
if value is None:
return ""
euro, cents = divmod(value, 100)
if cents:
return f"{unit}{euro}.{cents:02}"