aboutsummaryrefslogtreecommitdiff
path: root/management
diff options
context:
space:
mode:
Diffstat (limited to 'management')
-rw-r--r--management/commands/sendmails.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/management/commands/sendmails.py b/management/commands/sendmails.py
index 9a05a9c..b53d6f9 100644
--- a/management/commands/sendmails.py
+++ b/management/commands/sendmails.py
@@ -29,6 +29,9 @@ import datetime
class Command(BaseCommand):
help = "Sends emails to subscribed users"
+ def add_arguments(self, parser):
+ parser.add_argument("--test", help="Print the content of mails instead of sending them", action="store_true")
+
def handle(self, *args, **options):
translation.activate(settings.LANGUAGE_CODE)
@@ -51,10 +54,17 @@ class Command(BaseCommand):
context = Context({"courses": grouped_courses, "group": subscription.group, "week": week})
content[subscription.group.id] = timetable.render(context)
- 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],))
+ if options["test"]:
+ print(subscription.group)
+ print(content[subscription.group.id])
+
+ if not options["test"]:
+ 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],))
+
+ if not options["test"]:
+ print("Sending mails...")
+ send_mass_mail(mails)
- print("Sending mails...")
- send_mass_mail(mails)
self.stdout.write(self.style.SUCCESS("Done."))