diff options
author | Alban Gruin | 2017-02-26 22:08:08 +0100 |
---|---|---|
committer | Alban Gruin | 2017-02-26 22:08:08 +0100 |
commit | 0649ee9c528d7a3957fb65e195a4a56a702e8d48 (patch) | |
tree | d951b87b445fcfc92f21ebfc0e3913cb330407e8 /management | |
parent | cc479941c95fc487d1bbe8ed49af825177c55a81 (diff) |
Ajout du paramètre --test à la commande sendmails pour afficher les mails au lieu de les envoyer
Diffstat (limited to 'management')
-rw-r--r-- | management/commands/sendmails.py | 20 |
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.")) |