diff options
author | Alban Gruin | 2017-02-12 13:44:05 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-12 13:44:05 +0100 |
commit | a543aaa14957f390d2b640a264113b639c7d3194 (patch) | |
tree | 62bf0fdbd83717f3020dad2313dd1f4f4a9dcdce /management/commands | |
parent | 3d5d17475909a6b351fadf8bbdb0bf8dc8d8e928 (diff) | |
parent | 908ed3b4d0bc57131f6dafc663c6f7e098f0b7e1 (diff) |
Merge branch 'stable/0.y.z' into prod/pa1ch/0.y.zv0.6.0-pa1ch
Diffstat (limited to 'management/commands')
-rw-r--r-- | management/commands/sendmails.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py index 3126243..5a2054f 100644 --- a/management/commands/sendmails.py +++ b/management/commands/sendmails.py @@ -38,22 +38,25 @@ class Command(BaseCommand): subscriptions = Subscription.objects.filter(active=True) content = {} mails = [] + footer = loader.get_template("mail/mail_footer.txt") print("Generating messages...") for subscription in subscriptions: if subscription.group.id not in content: courses = Course.objects.get_courses_for_group(subscription.group, begin__gte=start, begin__lt=end) - grouped_courses = group_courses(courses) - 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 len(courses) > 0: + grouped_courses = group_courses(courses) - footer = loader.get_template("mail/mail_footer.txt") - context = Context({"admins": settings.ADMINS, "token": subscription.token, "domain": settings.DEFAULT_DOMAIN}) - mail_content = content[subscription.group.id] + footer.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) - mails.append(("{0} - {1} - Semaine {2}".format(subscription.group.timetable.name, subscription.group.name, week), mail_content, settings.DEFAULT_FROM_EMAIL, [subscription.email],)) + 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],)) print("Sending mails...") send_mass_mail(mails) |