# Society Self-Service # Copyright © 2018-2019 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 # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . from django.core.management.base import BaseCommand import ssmembership.models import sspromotions.models class Command(BaseCommand): help = 'Manually subscribe members' def add_arguments(self, parser): parser.add_argument('group') parser.add_argument('emailfile') def handle(self, *args, **options): group = sspromotions.models.Group.objects.get(name=args['group']) with open(args['emailfile'], 'r') as f: emails = set(f) for email in emails: email = email.strip() try: member = ssmembership.models.Member.objects.get(email=email) except ssmembership.models.Member.DoesNotExist: self.stdout.write('No such email: ' + email) continue if group.contains_member(member): self.stdout.write('Member already subscribed: ' + email) else: self.stdout.write('Subscribing new member: ' + email) group.subscribe_member(member, True)