1 from optparse import make_option
3 from django.core.management.base import BaseCommand, CommandError
4 from django.conf import settings
6 from wtem.models import Submission, DEBUG_KEY
9 class Command(BaseCommand):
10 help = 'Sends personalized links to WTEM contestants'
11 args = '<email_address1>, <email_address2>, ...'
13 option_list = BaseCommand.option_list + (
18 help='Use all available submissions'),
19 make_option('--force',
23 help='Force sending key even if one was already sent')
26 def handle(self, *args, **options):
27 if len(args) or options['all']:
28 return self.send_keys(*args, **options)
29 self.stdout.write('No submissions selected')
31 def send_keys(self, *args, **options):
36 query = Submission.objects.all()
37 if not options['force']:
38 query = query.filter(key_sent = False)
40 query = query.filter(email__in = args)
42 for submission in query.all():
43 assert len(submission.key) == 30 or (settings.DEBUG and submission.key == DEBUG_KEY)
46 self.send_key(submission)
49 self.stdout.write('failed sending to: ' + submission.email)
51 submission.key_sent = True
54 self.stdout.write('key sent to: ' + submission.email)
56 self.stdout.write('sent: ' + str(sent))
58 def send_key(self, submission):
59 self.stdout.write('>>> sending to ' + submission.email)