Fix bug on anonymous order view

Change to temporary message
This commit is contained in:
Midgard 2020-02-26 18:05:56 +01:00
parent 02cea73a6c
commit ccb034ef7f
Signed by: midgard
GPG key ID: 511C112F1331BBB4
3 changed files with 7 additions and 3 deletions

View file

@ -60,7 +60,7 @@ class OrderItemForm(Form):
else: else:
return "from {}".format(euro_string(price_range[0])) return "from {}".format(euro_string(price_range[0]))
def populate(self, location: Location, dish_id: Optional[str]) -> 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 + ": " + self.format_price_range(dish.price_range())))
for dish in location.dishes for dish in location.dishes

View file

@ -42,6 +42,9 @@
{% if form -%} {% if form -%}
<div class="col-md-push-1 col-md-10 darker order_order" id="form"> <div class="col-md-push-1 col-md-10 darker order_order" id="form">
<h4>Order:</h4> <h4>Order:</h4>
{% if current_user.is_anonymous() %}
<div>Sorry, anonymous ordering is currently broken. Please log in to order.</div>
{% else %}
<form method="post" action="{{ url_for('order_bp.order_item_create', order_id=order.id) }}"> <form method="post" action="{{ url_for('order_bp.order_item_create', order_id=order.id) }}">
<span class="pull-right"> <span class="pull-right">
<a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a> <a class="btn btn-primary" onclick="chooseRandom()">Choose for me</a>
@ -90,6 +93,7 @@
{{ form.submit_button(class='btn btn-primary') }} {{ form.submit_button(class='btn btn-primary') }}
</div> </div>
</form> </form>
{% endif %}
</div> </div>
{%- endif %} {%- endif %}
</div> </div>

View file

@ -60,7 +60,7 @@ def order_from_id(order_id: int, form: OrderForm = None, dish_id=None) -> str:
form = AnonOrderItemForm() if current_user.is_anonymous() \ form = AnonOrderItemForm() if current_user.is_anonymous() \
else OrderItemForm() else OrderItemForm()
if order.location: if order.location:
form.populate(order.location, None) form.populate(order.location)
if order.is_closed(): if order.is_closed():
form = None form = None
total_price = sum([o.price for o in order.items]) total_price = sum([o.price for o in order.items])
@ -130,7 +130,7 @@ def order_item_create(order_id: int) -> typing.Any:
if dish_id and not location.dish_by_id(dish_id): if dish_id and not location.dish_by_id(dish_id):
abort(404) abort(404)
form.dish_id.data = dish_id form.dish_id.data = dish_id
form.populate(current_order.location, dish_id) form.populate(current_order.location)
# If the form was not submitted (GET request), the form had errors, # If the form was not submitted (GET request), the form had errors,
# or the dish was changed: show form again # or the dish was changed: show form again