X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/fd65827f7d34921b927dfd735099b0690aa3a2df..1bbcf6254ccbfeeaa1aae9ec63d3582ef13ca5a6:/wtem/management/commands/wtem_send_results_csv.py diff --git a/wtem/management/commands/wtem_send_results_csv.py b/wtem/management/commands/wtem_send_results_csv.py index 0d15c17..a9d6e9a 100644 --- a/wtem/management/commands/wtem_send_results_csv.py +++ b/wtem/management/commands/wtem_send_results_csv.py @@ -3,35 +3,37 @@ from optparse import make_option from django.core.management.base import BaseCommand -from django.conf import settings -from wtem.management.commands import send_mail -from django.utils import translation from django.template.loader import render_to_string +from django.utils import translation -from contact.models import Contact +from wtem.management.commands import send_mail from wtem.models import Submission def get_submissions(): - return sorted(Submission.objects.exclude(answers = None).all(), key=lambda s: -s.final_result) + return sorted(Submission.objects.exclude(answers=None).all(), key=lambda s: -s.final_result) minimum = 55 + class Command(BaseCommand): args = 'csv_filename' option_list = BaseCommand.option_list + ( - make_option('--to-teachers', + make_option( + '--to-teachers', action='store_true', dest='to_teachers', default=False, help='Send emails to teachers'), - make_option('--to-students', + make_option( + '--to-students', action='store_true', dest='to_students', default=False, help='Send emails to students'), - make_option('--only-to', + make_option( + '--only-to', action='store', dest='only_to', default=None, @@ -67,11 +69,11 @@ class Command(BaseCommand): def handle_to_teachers(self, *args, **options): self.stdout.write('>>> Sending results to teachers') subject = 'Wyniki I etapu Wielkiego Turnieju Edukacji Medialnej' - failed = sent = 0 submissions_by_contact = dict() from decimal import Decimal, InvalidOperation + def dec_or_0(s): try: return Decimal(s) @@ -89,7 +91,7 @@ class Command(BaseCommand): for email, submissions in submissions_by_contact.items(): # contact = Contact.objects.get(id=contact_id) - message = render_to_string('wtem/results_teacher.txt', dict(submissions = submissions)) + message = render_to_string('wtem/results_teacher.txt', dict(submissions=submissions)) self.send_message(message, subject, email) self.sum_up() @@ -100,16 +102,10 @@ class Command(BaseCommand): def send_message(self, message, subject, email): self.stdout.write('>>> sending results to %s' % email) try: - send_mail( - subject = subject, - body = message, - to = [email] - ) + send_mail(subject=subject, body=message, to=[email]) except BaseException, e: self.failed += 1 self.stdout.write('failed sending to: ' + email + ': ' + str(e)) else: self.sent += 1 self.stdout.write('message sent to: ' + email) - -