From bc802cae425f3707258b0f6292343f0ed5d7a717 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sun, 24 Mar 2019 22:05:26 +0100 Subject: [PATCH] Allow to resend order by email --- copanier/__init__.py | 32 ++++++++++++++++++----------- copanier/emails.py | 17 ++++++++++++++- copanier/static/app.css | 8 ++++---- copanier/templates/place_order.html | 5 +++-- 4 files changed, 43 insertions(+), 19 deletions(-) diff --git a/copanier/__init__.py b/copanier/__init__.py index bcd88be..758727e 100644 --- a/copanier/__init__.py +++ b/copanier/__init__.py @@ -255,27 +255,35 @@ async def place_order(request, response, id): delivery.persist() if user and user.email == email: # Only send email if order has been placed by the user itself. - html = env.get_template("emails/order_summary.html").render( - order=order, delivery=delivery - ) - txt = env.get_template("emails/order_summary.txt").render( - order=order, delivery=delivery - ) - emails.send( - email, - f"Copanier: résumé de la commande {delivery.producer}", - body=txt, - html=html, + emails.send_order( + env, person=Person(email=email), delivery=delivery, order=order ) response.message(f"La commande pour «{email}» a bien été prise en compte!") response.redirect = f"/livraison/{delivery.id}" else: order = delivery.orders.get(email) or Order() response.html( - "place_order.html", {"delivery": delivery, "person": email, "order": order} + "place_order.html", + {"delivery": delivery, "person": Person(email=email), "order": order}, ) +@app.route("/livraison/{id}/courriel", methods=["GET"]) +@auth_required +async def send_order(request, response, id): + delivery = Delivery.load(id) + email = request.query.get("email") + order = delivery.orders.get(email) + if not order: + response.message(f"Aucune commande pour «{email}»", status="warning") + else: + emails.send_order( + env, person=Person(email=email), delivery=delivery, order=order + ) + response.message(f"Commande envoyée à «{email}»") + response.redirect = f"/livraison/{delivery.id}" + + @app.route("/livraison/{id}/émargement", methods=["GET"]) @auth_required async def signing_sheet(request, response, id): diff --git a/copanier/emails.py b/copanier/emails.py index 4f8bd85..402983c 100644 --- a/copanier/emails.py +++ b/copanier/emails.py @@ -21,7 +21,7 @@ def send(to, subject, body, html=None): msg["From"] = config.FROM_EMAIL msg["To"] = to if html: - msg.add_alternative(html, subtype='html') + msg.add_alternative(html, subtype="html") if not config.SEND_EMAILS: return print("Sending email", str(msg)) try: @@ -32,3 +32,18 @@ def send(to, subject, body, html=None): raise RuntimeError finally: server.quit() + + +def send_order(env, person, delivery, order): + html = env.get_template("emails/order_summary.html").render( + order=order, delivery=delivery + ) + txt = env.get_template("emails/order_summary.txt").render( + order=order, delivery=delivery + ) + send( + person.email, + f"Copanier: résumé de la commande {delivery.producer}", + body=txt, + html=html, + ) diff --git a/copanier/static/app.css b/copanier/static/app.css index 98847b1..e419d06 100644 --- a/copanier/static/app.css +++ b/copanier/static/app.css @@ -114,7 +114,7 @@ h4, h5, legend { /*margin: 0;*/ - color: var(--primary-color); + color: #444; line-height: 1; font-weight: 300; } @@ -376,7 +376,7 @@ hr { .notification { width: 100%; text-align: center; - color: #f1f1f1; + color: white; line-height: 3rem; height: 3rem; vertical-align: middle; @@ -387,8 +387,8 @@ hr { .notification.error { background-color: #e10055; } -.notification.error { - background-color: #8c5a2d; +.notification.warning { + background-color: #f9b42d; } .notification i { font-size: 2rem; diff --git a/copanier/templates/place_order.html b/copanier/templates/place_order.html index a1f1bb9..928c05d 100644 --- a/copanier/templates/place_order.html +++ b/copanier/templates/place_order.html @@ -2,7 +2,7 @@ {% block body %}
-

{{ delivery.producer }} — Commande de «{{ person }}»

+

{{ delivery.producer }} — Commande de «{{ person.email }}»

{% include "includes/delivery_head.html" %}
@@ -20,8 +20,9 @@ {% endfor %}

Total: {{ order.total(delivery.products) if order else 0 }} €

- + + Envoyer par courriel
{% endblock body %}