diff --git a/app/models/order.py b/app/models/order.py index 4e9f2bf..841271c 100644 --- a/app/models/order.py +++ b/app/models/order.py @@ -69,6 +69,9 @@ class Order(db.Model): return group + def is_closed(self) -> bool: + return datetime.now() > self.stoptime + def can_close(self, user_id: int) -> bool: "Check if a user can close the Order" if self.stoptime and self.stoptime < datetime.now(): diff --git a/app/static/css/main.css b/app/static/css/main.css index 03e8c6b..646270a 100644 --- a/app/static/css/main.css +++ b/app/static/css/main.css @@ -68,9 +68,18 @@ body { line-height: 1.2; } +.showcase { + padding: 0; + max-width: 500px; + margin: 0 auto; +} + .showcase h1 { - font-size: 150%; - font-weight: bold; + font-size: 200%; + margin: 0 ; + padding: 0.4em 0 0.2em; + border-bottom: 1px dashed var(--dGray1); + text-align: center; } .showcase h2 { font-size: 110%; @@ -78,6 +87,22 @@ body { margin-bottom: 0; } +.showcase .open-order-warning { + font-size: 150%; + text-align: center; + padding: 1em 0.5em; + background-color: rgba(255, 0, 0, 0.1); +} + +.showcase .dish { + padding: 0 0.5em; +} +@media (min-width: 500px) { + .showcase .dish { + padding: 0 1em; + } +} + .showcase .quantity { font-size: 110%; } @@ -89,6 +114,13 @@ body { margin: 0.7em 0 0.3em; } +.showcase .total { + border-top: 1px dashed var(--dGray1); + text-align: center; + padding: 0.5em 0; + margin-top: 1.3em; +} + .order_row { background: var(--dGray4); } diff --git a/app/templates/order.html b/app/templates/order.html index 1fc3b78..cfa2828 100644 --- a/app/templates/order.html +++ b/app/templates/order.html @@ -103,12 +103,14 @@ {% for key, value in order.group_by_dish().items() -%}
{{ key }}: {{ value["count"] }} - {% if value["comments"] -%} -
+ {% if value["comments"]|any -%} +
+ {%- endif %}
{%- endfor %} diff --git a/app/templates/order_items.html b/app/templates/order_items.html index 942a05f..fb479ee 100644 --- a/app/templates/order_items.html +++ b/app/templates/order_items.html @@ -15,30 +15,38 @@ Haldis - Order {{ order.id }} {% block scripts %} {{ super() }} + {% endblock %} {% block content -%} {{ utils.flashed_messages(container=True) }} -
-
-

Ordered dishes: {{ order.items.count() }}

- {% for key, value in order.group_by_dish().items() -%} -
-

{{ value["count"] }} × {{ key }}

- {% if value["comments"]|any -%} -
    - {% for comment in value["comments"] -%} -
  • {% if comment %}{{ comment }} - {% else %}No comment - {% endif %}
  • - {% endfor %} -
- {%- endif %} -

-
- {%- endfor %} +
+

Haldis order {{ order.id }}

+ + {% if not order.is_closed() %} +
+ {{ order.stoptime|countdown }}
+ Refresh page when closed!
+ {% endif %} + + {% for key, value in order.group_by_dish().items() -%} +
+

{{ value["count"] }} × {{ key }}

+ {% if value["comments"]|any -%} +
    + {% for comment in value["comments"] -%} +
  • {% if comment %}{{ comment }} + {% else %}No comment + {% endif %}
  • + {% endfor %} +
+ {%- endif %} +

+
+ {%- endfor %} +
Total {{ order.items.count() }} items — {{ total_price|euro }}
{%- endblock %} diff --git a/app/views/order.py b/app/views/order.py index bdc9776..9589939 100644 --- a/app/views/order.py +++ b/app/views/order.py @@ -75,7 +75,8 @@ def items_showcase(order_id: int) -> str: if current_user.is_anonymous() and not order.public: flash("Please login to see this order.", "info") abort(401) - return render_template("order_items.html", order=order) + total_price = sum([o.price for o in order.items]) + return render_template("order_items.html", order=order, total_price=total_price) @order_bp.route("//edit", methods=["GET", "POST"]) @@ -92,6 +93,7 @@ def order_edit(order_id: int) -> typing.Union[str, Response]: orderForm.populate() if orderForm.validate_on_submit(): orderForm.populate_obj(order) + order.update_from_hlds() db.session.commit() return redirect(url_for("order_bp.order_from_id", order_id=order.id)) return render_template("order_edit.html", form=orderForm, @@ -201,7 +203,7 @@ def volunteer(order_id: int) -> Response: order = Order.query.filter(Order.id == order_id).first() if order is None: abort(404) - if order.courier_id is None or order.courrier_id == 0: + if order.courier_id is None or order.courier_id == 0: order.courier_id = current_user.id db.session.commit() flash("Thank you for volunteering!") @@ -220,11 +222,11 @@ def close_order(order_id: int) -> typing.Optional[Response]: if (current_user.id == order.courier_id or current_user.is_admin()) and ( order.stoptime is None or (order.stoptime > datetime.now())): order.stoptime = datetime.now() - if order.courier_id == 0 or order.courrier_id is None: + if order.courier_id == 0 or order.courier_id is None: courier = select_user(order.items) print(courier) if courier is not None: - order.courier_id = courrier.id + order.courier_id = courier.id db.session.commit() return redirect(url_for("order_bp.order_from_id", order_id=order_id)) # The line below is to make sure mypy doesn't say