Add --all flag to send_renewal_email command
This commit is contained in:
parent
5059c5f793
commit
67060e0f04
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user