Add price range on location view
This commit is contained in:
parent
f2112ec26d
commit
45a110db23
4 changed files with 12 additions and 18 deletions
12
app/app.py
12
app/app.py
|
@ -18,7 +18,7 @@ from flask_script import Manager, Server
|
||||||
from login import init_login
|
from login import init_login
|
||||||
from models import db
|
from models import db
|
||||||
from models.anonymous_user import AnonymouseUser
|
from models.anonymous_user import AnonymouseUser
|
||||||
from utils import euro_string
|
from utils import euro_string, price_range_string
|
||||||
from zeus import init_oauth
|
from zeus import init_oauth
|
||||||
|
|
||||||
|
|
||||||
|
@ -159,15 +159,11 @@ def add_template_filters(app: Flask) -> None:
|
||||||
return time
|
return time
|
||||||
|
|
||||||
@app.template_filter("year")
|
@app.template_filter("year")
|
||||||
def current_year(value: typing.Any) -> str: # pylint: disable=W0613
|
def current_year(_value: typing.Any) -> str:
|
||||||
"A function which returns the current year"
|
|
||||||
return str(datetime.now().year)
|
return str(datetime.now().year)
|
||||||
|
|
||||||
@app.template_filter("euro")
|
app.template_filter("euro")(euro_string)
|
||||||
def euro(value: int) -> str:
|
app.template_filter("price_range")(price_range_string)
|
||||||
"A function which converts a value to its euro_string"
|
|
||||||
return euro_string(value)
|
|
||||||
|
|
||||||
app.template_filter("any")(any)
|
app.template_filter("any")(any)
|
||||||
|
|
||||||
|
|
||||||
|
|
11
app/forms.py
11
app/forms.py
|
@ -9,7 +9,7 @@ from flask_wtf import FlaskForm as Form
|
||||||
from wtforms import (DateTimeField, SelectField, SelectMultipleField, StringField, SubmitField,
|
from wtforms import (DateTimeField, SelectField, SelectMultipleField, StringField, SubmitField,
|
||||||
FieldList, validators)
|
FieldList, validators)
|
||||||
|
|
||||||
from utils import euro_string
|
from utils import euro_string, price_range_string
|
||||||
from hlds.definitions import location_definitions
|
from hlds.definitions import location_definitions
|
||||||
from hlds.models import Location, Dish, Choice
|
from hlds.models import Location, Dish, Choice
|
||||||
from models import User
|
from models import User
|
||||||
|
@ -53,16 +53,9 @@ class OrderItemForm(Form):
|
||||||
comment = StringField("Comment")
|
comment = StringField("Comment")
|
||||||
submit_button = SubmitField("Submit")
|
submit_button = SubmitField("Submit")
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def format_price_range(price_range):
|
|
||||||
if price_range[0] == price_range[1]:
|
|
||||||
return euro_string(price_range[0])
|
|
||||||
else:
|
|
||||||
return "from {}".format(euro_string(price_range[0]))
|
|
||||||
|
|
||||||
def populate(self, location: Location) -> None:
|
def populate(self, location: Location) -> None:
|
||||||
self.dish_id.choices = [
|
self.dish_id.choices = [
|
||||||
(dish.id, (dish.name + ": " + self.format_price_range(dish.price_range())))
|
(dish.id, (dish.name + ": " + price_range_string(dish.price_range())))
|
||||||
for dish in location.dishes
|
for dish in location.dishes
|
||||||
]
|
]
|
||||||
if not self.is_submitted() and self.comment.data is None:
|
if not self.is_submitted() and self.comment.data is None:
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ dish.name or dish.id }}</td>
|
<td>{{ dish.name or dish.id }}</td>
|
||||||
<td>{{ dish.description or "" }}</td>
|
<td>{{ dish.description or "" }}</td>
|
||||||
<td style="white-space: nowrap;">{{ dish.price|euro }}<td>
|
<td style="white-space: nowrap;">{{ dish.price_range()|price_range(true) }}<td>
|
||||||
</tr>
|
</tr>
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|
|
@ -9,6 +9,11 @@ def euro_string(value: int) -> str:
|
||||||
"""
|
"""
|
||||||
return "€ {}.{:02}".format(*divmod(value, 100))
|
return "€ {}.{:02}".format(*divmod(value, 100))
|
||||||
|
|
||||||
|
def price_range_string(price_range, include_upper=False):
|
||||||
|
if price_range[0] == price_range[1]:
|
||||||
|
return euro_string(price_range[0])
|
||||||
|
return ("{}—{}" if include_upper else "from {}").format(*map(euro_string, price_range))
|
||||||
|
|
||||||
|
|
||||||
def first(iterable: Iterable, default=None):
|
def first(iterable: Iterable, default=None):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue