[gsoc-admin] templates: Add arbitrary data source concept



commit ab9419191390d1d7cce8053dbc5086abebbaddb6
Author: Lasse Schuirmann <lasse schuirmann gmail com>
Date:   Thu Aug 13 15:24:52 2015 +0200

    templates: Add arbitrary data source concept
    
    Not implemented, obviously, but it could work that way.

 data/2015/students.csv                 |    6 +++---
 data/config.cfg                        |   26 ++++++++++++++++++++++++++
 data/templates/welcome_interns         |   12 ++++++++++++
 data/templates/welcome_interns_data.py |   17 +++++++++++++++++
 4 files changed, 58 insertions(+), 3 deletions(-)
---
diff --git a/data/2015/students.csv b/data/2015/students.csv
index 06bcb8b..ebbe37c 100644
--- a/data/2015/students.csv
+++ b/data/2015/students.csv
@@ -1,3 +1,3 @@
-mail,name
-lasse schuirmann gmail com,Lasse Schuirmann
-afranke gnome org,Alexandre Franke
+mail,name,mentor,project
+lasse schuirmann gmail com,Lasse Schuirmann,Zeeshan Ali Khattak,Boxes
+afranke gnome org,Alexandre Franke,Unknown,GSoC Administration
diff --git a/data/config.cfg b/data/config.cfg
index f4e8f72..d62ef84 100644
--- a/data/config.cfg
+++ b/data/config.cfg
@@ -1,3 +1,5 @@
+# DATA SOURCES
+
 [GSoC_Dates]
 type = ics_source
 #url = http://www.google.com/calendar/ical/gsummerofcode%%40gmail.com/public/basic.ics
@@ -7,11 +9,35 @@ path = data/basic.ics
 type = csv_source
 path = data/{year}/students.csv
 
+# DATES
+
 [FINAL_EVALS]
 type = date
 ics_source = GSoC_Dates
 description_regex = .*[fF]inal evaluation deadline.*
 
+[COMMUNITY_BONDING]
+type = date
+ics_source = GSoC_Dates
+description_regex = .*[cC]ommunity [bB]onding [pP]eriod.*
+
+# MAILS
+
+[WELCOME]
+type = mail_template
+path = data/templates/welcome_interns
+related_to = COMMUNITY_BONDING
+days_before = -3
+sender = lasse schuirmann gmail com
+recipients = GSoC_Students
+recipients_mail_column = mail
+recipients_name_column = name
+# Will import the get_data method from that file which should return a dict
+# holding all needed keys for this template. Method should accept one param
+# which is an EventConfig object holding all data referenced above in this
+# file.
+data_source = data/templates/welcome_interns_data.py
+
 [FOO]
 type = mail_template
 path = data/templates/foo
diff --git a/data/templates/welcome_interns b/data/templates/welcome_interns
new file mode 100644
index 0000000..32aed48
--- /dev/null
+++ b/data/templates/welcome_interns
@@ -0,0 +1,12 @@
+Dear interns, mentors and GNOME contributors,
+
+we hereby welcome all our interns and are happy to have the new
+mentors with us: {mentors} - welcome everyone!
+
+Cheers,
+
+Your GSoC Administrators
+
+---
+
+{projects}
diff --git a/data/templates/welcome_interns_data.py b/data/templates/welcome_interns_data.py
new file mode 100644
index 0000000..2318090
--- /dev/null
+++ b/data/templates/welcome_interns_data.py
@@ -0,0 +1,17 @@
+from maillib.config import EventConfig
+
+
+def get_data(event_config):
+    assert isinstance(event_config, EventConfig)
+    mentors = []
+    students = []
+    form_data = event_config.csvs['GSoC_Students']
+    for row in form_data:
+        mentors.append(row['mentor'])
+        student = "Name: {}\nMail: {}\nMentor: {}\nProject: {}\n" \
+                  .format(row['name'], row['mail'], row['mentor'],
+                          row['project'])
+        students.append(student)
+
+    return {'mentors': ', '.join(mentors),
+            'projects': '\n'.join(students)}


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