X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/8aed3ddd77e18349e044fbd8a817478cccf76009..602e4759c725ce5ba0eb37d27852d7a3bf7b48e4:/wtem/management/commands/wtem_send_results.py diff --git a/wtem/management/commands/wtem_send_results.py b/wtem/management/commands/wtem_send_results.py index 94c2653..c443ed1 100644 --- a/wtem/management/commands/wtem_send_results.py +++ b/wtem/management/commands/wtem_send_results.py @@ -13,9 +13,9 @@ from wtem.models import Submission def get_submissions(): - return Submission.objects.exclude(answers = None).all() + return sorted(Submission.objects.exclude(answers = None).all(), key=lambda s: -s.final_result) -minimum = 47.5 +minimum = 55 class Command(BaseCommand): @@ -30,6 +30,11 @@ class Command(BaseCommand): dest='to_students', default=False, help='Send emails to students'), + make_option('--only-to', + action='store', + dest='only_to', + default=None, + help='Send emails to students'), ) def handle(self, *args, **options): @@ -42,9 +47,11 @@ class Command(BaseCommand): def handle_to_students(self, *args, **options): self.stdout.write('>>> Sending results to students') - subject = 'Twój wynik w I etapie Wielkiego Turnieju Edukacji Medialnej' + subject = 'Wyniki I etapu Wielkiego Turnieju Edukacji Medialnej' for submission in get_submissions(): + if options['only_to'] and submission.email != options['only_to']: + continue final_result = submission.final_result if final_result < minimum: template = 'results_student_failed.txt' @@ -55,14 +62,16 @@ class Command(BaseCommand): self.sum_up() - def handle_to_teachers(self, *args, **kwargs): + def handle_to_teachers(self, *args, **options): self.stdout.write('>>> Sending results to teachers') - subject = 'Wyniki Twoich uczniów w I etapie Wielkiego Turnieju Edukacji Medialnej' + subject = 'Wyniki I etapu Wielkiego Turnieju Edukacji Medialnej' failed = sent = 0 submissions_by_contact = dict() for submission in get_submissions(): + if options['only_to'] and submission.contact.contact != options['only_to']: + continue submissions_by_contact.setdefault(submission.contact.id, []).append(submission) for contact_id, submissions in submissions_by_contact.items(): @@ -83,7 +92,7 @@ class Command(BaseCommand): body = message, to = [email] ) - except: + except BaseException, e: self.failed += 1 self.stdout.write('failed sending to: ' + email + ': ' + str(e)) else: