From 3e6505e2fa2da4f57e88c7bad02f49a133851734 Mon Sep 17 00:00:00 2001 From: Antoine Goutenoir Date: Thu, 2 Apr 2020 19:27:51 +0200 Subject: [PATCH] Add content to the emails sent. --- flaskr/controllers/main_controller.py | 24 ++++++++++++++++++++---- flaskr/templates/email/base.html | 13 +++++++++++++ flaskr/templates/email/run_completed.html | 12 ++++++++++++ flaskr/templates/email/run_failed.html | 23 +++++++++++++++++++++++ 4 files changed, 68 insertions(+), 4 deletions(-) create mode 100644 flaskr/templates/email/base.html create mode 100644 flaskr/templates/email/run_completed.html create mode 100644 flaskr/templates/email/run_failed.html diff --git a/flaskr/controllers/main_controller.py b/flaskr/controllers/main_controller.py index 31295a3..66f495f 100644 --- a/flaskr/controllers/main_controller.py +++ b/flaskr/controllers/main_controller.py @@ -49,7 +49,9 @@ OUT_ENCODING = 'utf-8' # ----------------------------------------------------------------------------- -pi_email = "didier.barret@irap.omp.eu" # todo: move to content YAML +pi_email = "didier.barret@irap.omp.eu" # todo: move to content YAML or .env +# pi_email = "goutte@protonmail.com" +base_url = "https://travel-footprint-calculator.irap.omp.eu/" # ----------------------------------------------------------------------------- @@ -240,7 +242,7 @@ def estimate(): # register new estimation request, more accurately send_email( to_recipient=pi_email, - subject="[TCFM] New Estimation: %s" % estimation.public_id, + subject="[TCFM] New Estimation Request: %s" % estimation.public_id, message="TODO" ) @@ -292,6 +294,15 @@ def compute(): # process the queue of estimation requests _estimation.status = StatusEnum.failure _estimation.errors = _failure_message db.session.commit() + send_email( + to_recipient=pi_email, + subject="[TCFM] Run failed: %s" % _estimation.public_id, + message=render_template( + 'email/run_failed.html', + base_url=base_url, + estimation=_estimation, + ) + ) def _handle_warning(_estimation, _warning_message): if not _estimation.warnings: @@ -668,11 +679,16 @@ def compute(): # process the queue of estimation requests send_email( to_recipient=pi_email, subject="[TCFM] Run completed: %s" % estimation.public_id, - message="TODO" + message=render_template( + 'email/run_completed.html', + base_url=base_url, + estimation=estimation, + ) ) # FINALLY, RESPOND #################################################### + # YAML is too expensive, let's not # response += yaml_dump(results) + "\n" return _respond(response) @@ -804,7 +820,7 @@ def dev_test(): import os # email_content = render_template( - # 'new_run.email.html', + # 'email/run_completed.html', # # run=run, # ) # send_email( diff --git a/flaskr/templates/email/base.html b/flaskr/templates/email/base.html new file mode 100644 index 0000000..2160d5f --- /dev/null +++ b/flaskr/templates/email/base.html @@ -0,0 +1,13 @@ +{% block content %}{% endblock %} + +{% block footer %} +

+ Thank you for using the + Travel Carbon Footprint Metacalculator. +

+ +

+ – Sincerely, + The Travel Carbon Footprint Metacalculator Team. +

+{% endblock %} diff --git a/flaskr/templates/email/run_completed.html b/flaskr/templates/email/run_completed.html new file mode 100644 index 0000000..e4ea550 --- /dev/null +++ b/flaskr/templates/email/run_completed.html @@ -0,0 +1,12 @@ +{% extends "email/base.html" %} + +{% block content %} +

+ Good news! + + The run {{ estimation.public_id }} has completed successfully. + + It is + available here. +

+{% endblock %} diff --git a/flaskr/templates/email/run_failed.html b/flaskr/templates/email/run_failed.html new file mode 100644 index 0000000..93212c7 --- /dev/null +++ b/flaskr/templates/email/run_failed.html @@ -0,0 +1,23 @@ +{% extends "email/base.html" %} + +{% block content %} +

+ OH, SNAP! + + The run {{ estimation.public_id }} has failed. +

+ +

+ Here's an excerpt of the caught errors:
+ +

+{{ estimation.errors }}
+    
+ +
+
+ + You can know more + on its page. +

+{% endblock %} -- libgit2 0.21.2