Add command to manually subscribe members
This commit is contained in:
parent
8fad94cd80
commit
1daffa2a08
47
sspromotions/management/commands/subscribemembers.py
Normal file
47
sspromotions/management/commands/subscribemembers.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
# 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
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)
|
Loading…
Reference in New Issue
Block a user