[gsoc-admin] EventConfig: Parse mail templates



commit e8d36234832bc03d3473beda9f7f9a5b2830ec4b
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Wed Aug 12 14:37:01 2015 +0200

    EventConfig: Parse mail templates

 data/config.cfg |    4 +++-
 email/config.py |   13 ++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)
---
diff --git a/data/config.cfg b/data/config.cfg
index db01259..41384eb 100644
--- a/data/config.cfg
+++ b/data/config.cfg
@@ -9,10 +9,12 @@ path = data/{year}/students
 [FINAL_EVALS]
 type = date
 ics_source = GSoC_Dates
-description_regex = .*[fF]inal evaluation deadline.*
+ics_description = .*[fF]inal evaluation deadline.*
 
 [FOO]
 type = mail_template
 path = data/templates/foo
 when = FINAL_EVALS - 3d
 recipients = GSoC_Students
+recipients_mail_column = email
+recipients_name_column = name
diff --git a/email/config.py b/email/config.py
index 02ca9c6..872708a 100644
--- a/email/config.py
+++ b/email/config.py
@@ -7,6 +7,8 @@ from ics import Calendar
 import re
 from urllib import request
 
+from email.email import Contact, EmailTemplate
+
 
 def apply_substitutions(uri):
     now = datetime.datetime.now()
@@ -70,7 +72,16 @@ class EventConfig:
         self.dates[section.name] = possible[0]
 
     def append_mail_from_section(self, section):
-        raise NotImplementedError
+        text = get_main_data_from_section(section)
+        recipients_mail_column = section['recipients_mail_column']
+        recipients_name_column = section.get('recipients_name_column', None)
+        recipients = []
+        for row in self.csvs[section['recipients']]:
+            mail = row[recipients_mail_column]
+            name = row.get(recipients_name_column, None)
+            recipients.append(Contact(mail, name))
+
+        self.mail_templates.append(EmailTemplate(text, recipients))
 
     def append_ics_from_section(self, section):
         ics_data = get_main_data_from_section(section)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]