Improve order items page and other stuff

This commit is contained in:
Midgard 2020-01-27 03:41:38 +01:00
parent 8ed38f178c
commit aa63023383
Signed by: midgard
GPG key ID: 511C112F1331BBB4
5 changed files with 75 additions and 28 deletions

View file

@ -69,6 +69,9 @@ class Order(db.Model):
return group return group
def is_closed(self) -> bool:
return datetime.now() > self.stoptime
def can_close(self, user_id: int) -> bool: def can_close(self, user_id: int) -> bool:
"Check if a user can close the Order" "Check if a user can close the Order"
if self.stoptime and self.stoptime < datetime.now(): if self.stoptime and self.stoptime < datetime.now():

View file

@ -68,9 +68,18 @@ body {
line-height: 1.2; line-height: 1.2;
} }
.showcase {
padding: 0;
max-width: 500px;
margin: 0 auto;
}
.showcase h1 { .showcase h1 {
font-size: 150%; font-size: 200%;
font-weight: bold; margin: 0 ;
padding: 0.4em 0 0.2em;
border-bottom: 1px dashed var(--dGray1);
text-align: center;
} }
.showcase h2 { .showcase h2 {
font-size: 110%; font-size: 110%;
@ -78,6 +87,22 @@ body {
margin-bottom: 0; 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 { .showcase .quantity {
font-size: 110%; font-size: 110%;
} }
@ -89,6 +114,13 @@ body {
margin: 0.7em 0 0.3em; 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 { .order_row {
background: var(--dGray4); background: var(--dGray4);
} }

View file

@ -103,12 +103,14 @@
{% for key, value in order.group_by_dish().items() -%} {% for key, value in order.group_by_dish().items() -%}
<div class="product"> <div class="product">
{{ key }}: {{ value["count"] }} {{ key }}: {{ value["count"] }}
{% if value["comments"] -%} {% if value["comments"]|any -%}
<div class="comments"> <ul class="comments">
{% for comment in value["comments"] -%} {% for comment in value["comments"] -%}
<div>- {{ comment }}</div> <li>{% if comment %}{{ comment }}
{% else %}<i>No comment</i>
{% endif %}</li>
{% endfor %} {% endfor %}
</div> </ul>
{%- endif %} {%- endif %}
</div> </div>
{%- endfor %} {%- endfor %}

View file

@ -15,14 +15,22 @@ Haldis - Order {{ order.id }}
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script> <script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='js/timer.js') }}"></script>
{% endblock %} {% endblock %}
{% block content -%} {% block content -%}
{{ utils.flashed_messages(container=True) }} {{ utils.flashed_messages(container=True) }}
<div class="row"> <div class="darker showcase" id="items-ordered">
<div class="col-sm-6 col-sm-offset-3 darker showcase" id="items-ordered"> <h1>Haldis order {{ order.id }}</h1>
<h1 class="text-center">Ordered dishes: {{ order.items.count() }}</h1>
{% if not order.is_closed() %}
<div class="open-order-warning">
<span class="time">{{ order.stoptime|countdown }}</span><br/>
Refresh page when closed!
</div>
{% endif %}
{% for key, value in order.group_by_dish().items() -%} {% for key, value in order.group_by_dish().items() -%}
<div class="dish"> <div class="dish">
<h2><span class="quantity">{{ value["count"] }}</span> × {{ key }}</h2> <h2><span class="quantity">{{ value["count"] }}</span> × {{ key }}</h2>
@ -38,7 +46,7 @@ Haldis - Order {{ order.id }}
</p> </p>
</div> </div>
{%- endfor %} {%- endfor %}
</div> <div class="total">Total {{ order.items.count() }} items — {{ total_price|euro }}</div>
</div> </div>
{%- endblock %} {%- endblock %}

View file

@ -75,7 +75,8 @@ def items_showcase(order_id: int) -> str:
if current_user.is_anonymous() and not order.public: if current_user.is_anonymous() and not order.public:
flash("Please login to see this order.", "info") flash("Please login to see this order.", "info")
abort(401) 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("/<order_id>/edit", methods=["GET", "POST"]) @order_bp.route("/<order_id>/edit", methods=["GET", "POST"])
@ -92,6 +93,7 @@ def order_edit(order_id: int) -> typing.Union[str, Response]:
orderForm.populate() orderForm.populate()
if orderForm.validate_on_submit(): if orderForm.validate_on_submit():
orderForm.populate_obj(order) orderForm.populate_obj(order)
order.update_from_hlds()
db.session.commit() db.session.commit()
return redirect(url_for("order_bp.order_from_id", order_id=order.id)) return redirect(url_for("order_bp.order_from_id", order_id=order.id))
return render_template("order_edit.html", form=orderForm, 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() order = Order.query.filter(Order.id == order_id).first()
if order is None: if order is None:
abort(404) 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 order.courier_id = current_user.id
db.session.commit() db.session.commit()
flash("Thank you for volunteering!") 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 ( if (current_user.id == order.courier_id or current_user.is_admin()) and (
order.stoptime is None or (order.stoptime > datetime.now())): order.stoptime is None or (order.stoptime > datetime.now())):
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) courier = select_user(order.items)
print(courier) print(courier)
if courier is not None: if courier is not None:
order.courier_id = courrier.id order.courier_id = courier.id
db.session.commit() db.session.commit()
return redirect(url_for("order_bp.order_from_id", order_id=order_id)) return redirect(url_for("order_bp.order_from_id", order_id=order_id))
# The line below is to make sure mypy doesn't say # The line below is to make sure mypy doesn't say