From 67060e0f04b90e17b9bacd4edab90b651c343b06 Mon Sep 17 00:00:00 2001 From: Yingtong Li Date: Tue, 1 Mar 2022 19:10:57 +1100 Subject: [PATCH] Add --all flag to send_renewal_email command --- .../management/commands/send_renewal_email.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ssmembership/management/commands/send_renewal_email.py b/ssmembership/management/commands/send_renewal_email.py index 08e9f26..26722b5 100644 --- a/ssmembership/management/commands/send_renewal_email.py +++ b/ssmembership/management/commands/send_renewal_email.py @@ -1,5 +1,5 @@ # Society Self-Service -# Copyright © 2018-2020 Yingtong Li (RunasSudo) +# Copyright © 2018-2022 Yingtong Li (RunasSudo) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by @@ -35,8 +35,9 @@ class Command(BaseCommand): help = 'Send emails for membership renewal' def add_arguments(self, parser): - parser.add_argument('ids', nargs='*', type=int, help='Members with ID numbers equal to these values will be emailed (default all)') - parser.add_argument('--render', action='store_true', help='Render to stdout instead of sending emails') + parser.add_argument('ids', nargs='*', type=int, help='Members with ID numbers equal to these values will be emailed') + parser.add_argument('--all', action='store_true', help='Email all members rather than only specified IDs') + #parser.add_argument('--render', action='store_true', help='Render to stdout instead of sending emails') def handle(self, *args, **options): today = timezone.localtime(timezone.now()).date() @@ -44,14 +45,15 @@ class Command(BaseCommand): template_html = loader.get_template('ssmembership/email/renew.html') template_txt = loader.get_template('ssmembership/email/renew.txt') - if len(options['ids']) > 0: + if options['all']: + members = models.Member.objects.all() + elif len(options['ids']) > 0: members = models.Member.objects.filter(id__in=options['ids']) else: - raise Exception('Must provide IDs') + raise Exception('Must provide IDs or specify --all') emailer = Emailer() for member in members: - #import pdb; pdb.set_trace() if member.member_type != 1 or member.expires < today or member.expires > today.replace(month=12, day=31): self.stdout.write('Skipping {} at {}'.format(member.id, member.email)) continue