From 7fdc3464c193740ebb0d8d4f6dfc2960dc598ee4 Mon Sep 17 00:00:00 2001
From: Robin Sonnabend <robin@fsmpi.rwth-aachen.de>
Date: Fri, 7 Jul 2017 20:02:45 +0200
Subject: [PATCH] Add option for additional todomail providers

/close #76
---
 config.py.example |  9 +++++++++
 tasks.py          | 12 ++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/config.py.example b/config.py.example
index 993e68b..41fc0e6 100644
--- a/config.py.example
+++ b/config.py.example
@@ -157,3 +157,12 @@ LATEX_BULLETPOINTS = [
 # optional: include header and footer in asta-style, not just a page number on top
 #LATEX_HEADER_FOOTER = True
 
+HTML_LEVEL_OFFSET = 3
+
+def dummy_todomail_provider():
+    return {"example": ("Name", "mail@example.com")}
+
+# list of functions that return dicts mapping todomail-keys to a tuple containing name and mail address
+ADDITIONAL_TODOMAIL_PROVIDERS = [
+    dummy_todomail_provider
+]
diff --git a/tasks.py b/tasks.py
index f393309..9e214be 100644
--- a/tasks.py
+++ b/tasks.py
@@ -611,8 +611,20 @@ def send_todomails_async(protocol_id):
             for user in users
         }
         subject = "Du hast noch was zu tun!"
+        todomail_providers = getattr(config, "ADDITIONAL_TODOMAIL_PROVIDERS", None)
+        additional_todomails = {}
+        if todomail_providers:
+            for provider in todomail_providers:
+                todomail_dict = provider()
+                for key in todomail_dict:
+                    if key not in additional_todomails:
+                        name, mail = todomail_dict[key]
+                        additional_todomails[key] = TodoMail(name, mail)
         for user in users:
             todomail = TodoMail.query.filter(TodoMail.name.ilike(user)).first()
+            if todomail is None:
+                if user in additional_todomails:
+                    todomail = additional_todomails[user]
             if todomail is None:
                 error = protocol.create_error("Sending Todomail", "Sending Todomail failed.", "User {} has no Todo-Mail-Assignment.".format(user))
                 db.session.add(error)
-- 
GitLab