X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/a2990772dfc18c810d16561ce4abbcaabc9f3637..243f4c5eef6c3f1d6e6d2875080e5830cf5382a8:/wtem/management/commands/wtem_send_keys.py?ds=sidebyside diff --git a/wtem/management/commands/wtem_send_keys.py b/wtem/management/commands/wtem_send_keys.py index cff7bf3..4a1760c 100644 --- a/wtem/management/commands/wtem_send_keys.py +++ b/wtem/management/commands/wtem_send_keys.py @@ -1,11 +1,10 @@ # -*- coding: utf-8 -*- -import sys from optparse import make_option -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from django.conf import settings -from django.core.mail import send_mail +from wtem.management.commands import send_mail from django.template.loader import render_to_string from wtem.models import Submission, DEBUG_KEY @@ -16,12 +15,14 @@ class Command(BaseCommand): args = ', , ...' option_list = BaseCommand.option_list + ( - make_option('--all', + make_option( + '--all', action='store_true', dest='all', default=False, help='Use all available submissions'), - make_option('--force', + make_option( + '--force', action='store_true', dest='force', default=False, @@ -35,23 +36,22 @@ class Command(BaseCommand): def send_keys(self, *args, **options): sent = 0 - skipped = 0 failed = 0 - query = Submission.objects.all() + submissions = Submission.objects.all() if not options['force']: - query = query.filter(key_sent = False) + submissions = submissions.filter(key_sent=False) if len(args): - query = query.filter(email__in = args) + submissions = submissions.filter(email__in=args) - for submission in query.all(): + for submission in submissions: 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)) + self.stdout.write('failed sending to: ' + submission.email + ' - ' + repr(e)) else: submission.key_sent = True submission.save() @@ -63,9 +63,6 @@ class Command(BaseCommand): 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 + subject="Olimpiada Cyfrowa - Twój link do zadań I etapu", + body=render_to_string('wtem/email_key.txt', dict(submission=submission)), + to=[submission.email])