aboutsummaryrefslogtreecommitdiff
path: root/management/commands/sendmails.py
diff options
context:
space:
mode:
authorAlban Gruin2017-02-13 12:25:18 +0100
committerAlban Gruin2017-02-13 12:25:18 +0100
commitd91081d8539988aaca426022c3f28ad78a024bea (patch)
treea4fef5d90d3092b586536d4099b6ceb38c7fbd94 /management/commands/sendmails.py
parente9ec8bdb5dfcb5735bec4a00611e69ad768181c0 (diff)
Ajout d'un mail pour signaler l'absence de cours pendant la semaine
Diffstat (limited to 'management/commands/sendmails.py')
-rw-r--r--management/commands/sendmails.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py
index 5a2054f..e30bb1b 100644
--- a/management/commands/sendmails.py
+++ b/management/commands/sendmails.py
@@ -38,7 +38,10 @@ class Command(BaseCommand):
subscriptions = Subscription.objects.filter(active=True)
content = {}
mails = []
+
footer = loader.get_template("mail/mail_footer.txt")
+ no_event = loader.get_template("mail/mail_noevent.txt")
+ timetable = loader.get_template("mail/mail_timetable.txt")
print("Generating messages...")
for subscription in subscriptions:
@@ -47,16 +50,15 @@ class Command(BaseCommand):
if len(courses) > 0:
grouped_courses = group_courses(courses)
+ context = Context({"courses": grouped_courses, "week": week})
+ content[subscription.group.id] = timetable.render(context)
+ else:
+ context = Context({"group": subscription.group, "week": week})
+ content[subscription.group.id] = no_event.render(context)
- template = loader.get_template("mail/mail_timetable.txt")
- context = Context({"subscription": subscription, "courses": grouped_courses, "week": week})
- content[subscription.group.id] = template.render(context)
-
- if subscription.group.id in content:
- context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
- mail_content = content[subscription.group.id] + footer.render(context)
-
- mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable.name, subscription.group.name, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],))
+ context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN})
+ mail_content = content[subscription.group.id] + footer.render(context)
+ mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable.name, subscription.group.name, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],))
print("Sending mails...")
send_mass_mail(mails)