Commit 3e6505e2fa2da4f57e88c7bad02f49a133851734
1 parent
04d423cb
Exists in
master
Add content to the emails sent.
We use jinja's templates as well there, for convenience.
Showing
4 changed files
with
68 additions
and
4 deletions
Show diff stats
flaskr/controllers/main_controller.py
@@ -49,7 +49,9 @@ OUT_ENCODING = 'utf-8' | @@ -49,7 +49,9 @@ OUT_ENCODING = 'utf-8' | ||
49 | 49 | ||
50 | # ----------------------------------------------------------------------------- | 50 | # ----------------------------------------------------------------------------- |
51 | 51 | ||
52 | -pi_email = "didier.barret@irap.omp.eu" # todo: move to content YAML | 52 | +pi_email = "didier.barret@irap.omp.eu" # todo: move to content YAML or .env |
53 | +# pi_email = "goutte@protonmail.com" | ||
54 | +base_url = "https://travel-footprint-calculator.irap.omp.eu/" | ||
53 | 55 | ||
54 | # ----------------------------------------------------------------------------- | 56 | # ----------------------------------------------------------------------------- |
55 | 57 | ||
@@ -240,7 +242,7 @@ def estimate(): # register new estimation request, more accurately | @@ -240,7 +242,7 @@ def estimate(): # register new estimation request, more accurately | ||
240 | 242 | ||
241 | send_email( | 243 | send_email( |
242 | to_recipient=pi_email, | 244 | to_recipient=pi_email, |
243 | - subject="[TCFM] New Estimation: %s" % estimation.public_id, | 245 | + subject="[TCFM] New Estimation Request: %s" % estimation.public_id, |
244 | message="TODO" | 246 | message="TODO" |
245 | ) | 247 | ) |
246 | 248 | ||
@@ -292,6 +294,15 @@ def compute(): # process the queue of estimation requests | @@ -292,6 +294,15 @@ def compute(): # process the queue of estimation requests | ||
292 | _estimation.status = StatusEnum.failure | 294 | _estimation.status = StatusEnum.failure |
293 | _estimation.errors = _failure_message | 295 | _estimation.errors = _failure_message |
294 | db.session.commit() | 296 | db.session.commit() |
297 | + send_email( | ||
298 | + to_recipient=pi_email, | ||
299 | + subject="[TCFM] Run failed: %s" % _estimation.public_id, | ||
300 | + message=render_template( | ||
301 | + 'email/run_failed.html', | ||
302 | + base_url=base_url, | ||
303 | + estimation=_estimation, | ||
304 | + ) | ||
305 | + ) | ||
295 | 306 | ||
296 | def _handle_warning(_estimation, _warning_message): | 307 | def _handle_warning(_estimation, _warning_message): |
297 | if not _estimation.warnings: | 308 | if not _estimation.warnings: |
@@ -668,11 +679,16 @@ def compute(): # process the queue of estimation requests | @@ -668,11 +679,16 @@ def compute(): # process the queue of estimation requests | ||
668 | send_email( | 679 | send_email( |
669 | to_recipient=pi_email, | 680 | to_recipient=pi_email, |
670 | subject="[TCFM] Run completed: %s" % estimation.public_id, | 681 | subject="[TCFM] Run completed: %s" % estimation.public_id, |
671 | - message="TODO" | 682 | + message=render_template( |
683 | + 'email/run_completed.html', | ||
684 | + base_url=base_url, | ||
685 | + estimation=estimation, | ||
686 | + ) | ||
672 | ) | 687 | ) |
673 | 688 | ||
674 | # FINALLY, RESPOND #################################################### | 689 | # FINALLY, RESPOND #################################################### |
675 | 690 | ||
691 | + # YAML is too expensive, let's not | ||
676 | # response += yaml_dump(results) + "\n" | 692 | # response += yaml_dump(results) + "\n" |
677 | 693 | ||
678 | return _respond(response) | 694 | return _respond(response) |
@@ -804,7 +820,7 @@ def dev_test(): | @@ -804,7 +820,7 @@ def dev_test(): | ||
804 | import os | 820 | import os |
805 | 821 | ||
806 | # email_content = render_template( | 822 | # email_content = render_template( |
807 | - # 'new_run.email.html', | 823 | + # 'email/run_completed.html', |
808 | # # run=run, | 824 | # # run=run, |
809 | # ) | 825 | # ) |
810 | # send_email( | 826 | # send_email( |
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +{% block content %}{% endblock %} | ||
2 | + | ||
3 | +{% block footer %} | ||
4 | +<p> | ||
5 | + Thank you for using the | ||
6 | + <em>Travel Carbon Footprint Metacalculator</em>. | ||
7 | +</p> | ||
8 | + | ||
9 | +<p> | ||
10 | + – Sincerely, | ||
11 | + <em>The Travel Carbon Footprint Metacalculator Team.</em> | ||
12 | +</p> | ||
13 | +{% endblock %} |
@@ -0,0 +1,12 @@ | @@ -0,0 +1,12 @@ | ||
1 | +{% extends "email/base.html" %} | ||
2 | + | ||
3 | +{% block content %} | ||
4 | +<p> | ||
5 | + Good news! | ||
6 | + | ||
7 | + The run <code>{{ estimation.public_id }}</code> has completed successfully. | ||
8 | + | ||
9 | + It is | ||
10 | + <strong><a href="{{ base_url }}/estimation/{{ estimation.public_id }}.html">available here</a></strong>. | ||
11 | +</p> | ||
12 | +{% endblock %} |
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +{% extends "email/base.html" %} | ||
2 | + | ||
3 | +{% block content %} | ||
4 | +<p> | ||
5 | + OH, SNAP! | ||
6 | + | ||
7 | + The run <code>{{ estimation.public_id }}</code> has failed. | ||
8 | +</p> | ||
9 | + | ||
10 | +<p> | ||
11 | + Here's an excerpt of the caught errors: <br> | ||
12 | + | ||
13 | + <pre style="color: darkred"> | ||
14 | +{{ estimation.errors }} | ||
15 | + </pre> | ||
16 | + | ||
17 | + <br> | ||
18 | + <br> | ||
19 | + | ||
20 | + You can know more | ||
21 | + <strong><a href="{{ base_url }}/estimation/{{ estimation.public_id }}.html">on its page</a></strong>. | ||
22 | +</p> | ||
23 | +{% endblock %} |