--- /dev/null
+from optparse import make_option
+
+from django.core.management.base import BaseCommand, CommandError
+from django.conf import settings
+
+from wtem.models import Submission, DEBUG_KEY
+
+
+class Command(BaseCommand):
+ help = 'Sends personalized links to WTEM contestants'
+ args = '<email_address1>, <email_address2>, ...'
+
+ option_list = BaseCommand.option_list + (
+ make_option('--all',
+ action='store_true',
+ dest='all',
+ default=False,
+ help='Use all available submissions'),
+ make_option('--force',
+ action='store_true',
+ dest='force',
+ default=False,
+ help='Force sending key even if one was already sent')
+ )
+
+ def handle(self, *args, **options):
+ if len(args) or options['all']:
+ return self.send_keys(*args, **options)
+ self.stdout.write('No submissions selected')
+
+ def send_keys(self, *args, **options):
+ sent = 0
+ skipped = 0
+ failed = 0
+
+ query = Submission.objects.all()
+ if not options['force']:
+ query = query.filter(key_sent = False)
+ if len(args):
+ query = query.filter(email__in = args)
+
+ for submission in query.all():
+ assert len(submission.key) == 30 or (settings.DEBUG and submission.key == DEBUG_KEY)
+
+ try:
+ self.send_key(submission)
+ except:
+ failed += 1
+ self.stdout.write('failed sending to: ' + submission.email)
+ else:
+ submission.key_sent = True
+ submission.save()
+ sent += 1
+ self.stdout.write('key sent to: ' + submission.email)
+
+ self.stdout.write('sent: ' + str(sent))
+
+ def send_key(self, submission):
+ self.stdout.write('>>> sending to ' + submission.email)
\ No newline at end of file
--- /dev/null
+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+ # Adding field 'Submission.key_sent'
+ db.add_column(u'wtem_submission', 'key_sent',
+ self.gf('django.db.models.fields.BooleanField')(default=False),
+ keep_default=False)
+
+
+ def backwards(self, orm):
+ # Deleting field 'Submission.key_sent'
+ db.delete_column(u'wtem_submission', 'key_sent')
+
+
+ models = {
+ u'contact.contact': {
+ 'Meta': {'ordering': "('-created_at',)", 'object_name': 'Contact'},
+ 'body': ('jsonfield.fields.JSONField', [], {'default': '{}'}),
+ 'contact': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'form_tag': ('django.db.models.fields.CharField', [], {'max_length': '32', 'db_index': 'True'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'ip': ('django.db.models.fields.IPAddressField', [], {'max_length': '15'})
+ },
+ u'wtem.attachment': {
+ 'Meta': {'object_name': 'Attachment'},
+ 'file': ('django.db.models.fields.files.FileField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'submission': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['wtem.Submission']"})
+ },
+ u'wtem.submission': {
+ 'Meta': {'object_name': 'Submission'},
+ 'answers': ('django.db.models.fields.CharField', [], {'max_length': '65536', 'null': 'True', 'blank': 'True'}),
+ 'contact': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contact.Contact']", 'null': 'True'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'unique': 'True', 'max_length': '100'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}),
+ 'key_sent': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ }
+ }
+
+ complete_apps = ['wtem']
\ No newline at end of file