diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-09-05 13:16:52 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-09-05 13:16:52 +0100 |
| commit | b92cac0254c1014f4873343c38fc5b6ccbe3337d (patch) | |
| tree | a4cac96ac91a5b60900aa6b790a2685c29044918 /app | |
| parent | Change percentage to percentage of target (diff) | |
| download | AnnotateChange-b92cac0254c1014f4873343c38fc5b6ccbe3337d.tar.gz AnnotateChange-b92cac0254c1014f4873343c38fc5b6ccbe3337d.zip | |
Email the annotation record as a backup
Diffstat (limited to 'app')
| -rw-r--r-- | app/main/email.py | 25 | ||||
| -rw-r--r-- | app/main/routes.py | 10 | ||||
| -rw-r--r-- | app/templates/email/annotation_record.html | 2 | ||||
| -rw-r--r-- | app/templates/email/annotation_record.txt | 3 |
4 files changed, 40 insertions, 0 deletions
diff --git a/app/main/email.py b/app/main/email.py new file mode 100644 index 0000000..c10e234 --- /dev/null +++ b/app/main/email.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +import json + +from flask import current_app, render_template + +from app.email import send_email + + +def send_annotation_backup(record): + pretty_record = json.dumps(record, sort_keys=True, indent=4) + subject = "[Backup] New Annotation Recorded" + if current_app.debug: + subject += " (debug)" + send_email( + subject, + sender=current_app.config["ADMINS"][0], + recipients=[current_app.config["ADMINS"][0]], + text_body=render_template( + "email/annotation_record.txt", pretty_record=pretty_record + ), + html_body=render_template( + "email/annotation_record.html", pretty_record=pretty_record + ), + ) diff --git a/app/main/routes.py b/app/main/routes.py index 85e8144..b961b60 100644 --- a/app/main/routes.py +++ b/app/main/routes.py @@ -9,6 +9,7 @@ from flask_login import current_user from app import db from app.decorators import login_required from app.main import bp +from app.main.email import send_annotation_backup from app.models import Annotation, Task from app.utils.datasets import load_data_for_chart from app.utils.tasks import generate_user_task @@ -84,6 +85,15 @@ def annotate(task_id): db.session.commit() flash("Your annotation has been recorded, thank you!", "success") + # send the annotation as email to the admin for backup + record = { + "user_id": task.annotator_id, + "dataset_id": task.dataset_id, + "task_id": task.id, + "annotations_raw": annotation, + } + send_annotation_backup(record) + # assign a new task if necessary task = generate_user_task(current_user) if task is None: diff --git a/app/templates/email/annotation_record.html b/app/templates/email/annotation_record.html new file mode 100644 index 0000000..a85b0b1 --- /dev/null +++ b/app/templates/email/annotation_record.html @@ -0,0 +1,2 @@ +<p>A new annotation has been recorded:</p> +<pre>{{ pretty_record }}</pre> diff --git a/app/templates/email/annotation_record.txt b/app/templates/email/annotation_record.txt new file mode 100644 index 0000000..6e1438d --- /dev/null +++ b/app/templates/email/annotation_record.txt @@ -0,0 +1,3 @@ +A new annotation has been recorded: + +{{ pretty_record }} |
