X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/a2990772dfc18c810d16561ce4abbcaabc9f3637..d555d988764995ea1f9f5ece46f453a66f09b334:/wtem/management/commands/wtem_send_keys.py diff --git a/wtem/management/commands/wtem_send_keys.py b/wtem/management/commands/wtem_send_keys.py deleted file mode 100644 index cff7bf3..0000000 --- a/wtem/management/commands/wtem_send_keys.py +++ /dev/null @@ -1,71 +0,0 @@ -# -*- coding: utf-8 -*- - -import sys -from optparse import make_option - -from django.core.management.base import BaseCommand, CommandError -from django.conf import settings -from django.core.mail import send_mail -from django.template.loader import render_to_string - -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 Exception as e: - failed += 1 - self.stdout.write('failed sending to: ' + submission.email + ' - ' + str(e)) - 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) - send_mail( - "WTEM - Twój link do zadań", - render_to_string('wtem/email_key.txt', dict(submission = submission)), - getattr(settings, 'WTEM_CONTACT_EMAIL', 'no-reply@edukacjamedialna.edu.pl'), - [submission.email], - fail_silently=False - ) \ No newline at end of file