From: Aleksander Ɓukasz Date: Tue, 5 Nov 2013 12:13:18 +0000 (+0100) Subject: Sending keys wip: up to point of actually sending an email X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/53907d17526cecf92207417e051527c00bcd2426?ds=sidebyside Sending keys wip: up to point of actually sending an email --- diff --git a/wtem/management/commands/wtem_send_keys.py b/wtem/management/commands/wtem_send_keys.py new file mode 100644 index 0000000..82e7469 --- /dev/null +++ b/wtem/management/commands/wtem_send_keys.py @@ -0,0 +1,59 @@ +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 = ', , ...' + + 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 diff --git a/wtem/migrations/0002_auto__add_field_submission_key_sent.py b/wtem/migrations/0002_auto__add_field_submission_key_sent.py new file mode 100644 index 0000000..825da07 --- /dev/null +++ b/wtem/migrations/0002_auto__add_field_submission_key_sent.py @@ -0,0 +1,52 @@ +# -*- 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 diff --git a/wtem/models.py b/wtem/models.py index 30539b2..75fa0ba 100644 --- a/wtem/models.py +++ b/wtem/models.py @@ -15,6 +15,7 @@ class Submission(models.Model): last_name = models.CharField(max_length = 100) email = models.EmailField(max_length = 100, unique = True) answers = models.CharField(max_length = 65536, null = True, blank = True) + key_sent = models.BooleanField(default = False) @classmethod def generate_key(cls):