From: Jan Szejko Date: Mon, 20 Mar 2017 10:58:44 +0000 (+0100) Subject: send results for stage 2 X-Git-Url: https://git.mdrn.pl/edumed.git/commitdiff_plain/adee5f3fa0d69d1b5face1f8f32a6080f11ece41 send results for stage 2 --- diff --git a/stage2/management/commands/stage2_send_results.py b/stage2/management/commands/stage2_send_results.py new file mode 100644 index 0000000..68ec664 --- /dev/null +++ b/stage2/management/commands/stage2_send_results.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +from optparse import make_option + +from django.core.management.base import BaseCommand +from wtem.management.commands import send_mail +from django.utils import translation +from django.template.loader import render_to_string + +from stage2.models import Participant + + +def get_participants(): + return sorted(Participant.objects.filter(complete_set=True), key=lambda s: -s.score()) + +minimum = 55 + + +class Command(BaseCommand): + + option_list = BaseCommand.option_list + ( + make_option( + '--to-teachers', + action='store_true', + dest='to_teachers', + default=False, + help='Send emails to teachers'), + make_option( + '--to-students', + action='store_true', + dest='to_students', + default=False, + help='Send emails to students'), + make_option( + '--only-to', + action='store', + dest='only_to', + default=None, + help='Send email only to one address'), + ) + + def __init__(self): + super(Command, self).__init__() + self.sent = self.failed = None + + def handle(self, *args, **options): + translation.activate('pl') + for target in ['to_teachers', 'to_students']: + if options[target]: + self.sent = 0 + self.failed = 0 + getattr(self, 'handle_' + target)(*args, **options) + + def handle_to_students(self, *args, **options): + self.stdout.write('>>> Sending results to students') + subject = 'Wyniki II etapu Olimpiady Cyfrowej' + + for participant in get_participants(): + if options['only_to'] and participant.email != options['only_to']: + continue + final_result = participant.score() + if final_result < minimum: + template = 'results_student_failed.txt' + else: + template = 'results_student_passed.txt' + message = render_to_string('stage2/' + template, dict(final_result=final_result)) + self.send_message(message, subject, participant.email) + + self.sum_up() + + def handle_to_teachers(self, *args, **options): + self.stdout.write('>>> Sending results to teachers') + subject = 'Wyniki II etapu Olimpiady Cyfrowej' + + participants_by_contact = defaultdict(list) + + for participant in get_participants(): + if options['only_to'] and participant.contact.contact != options['only_to']: + continue + participants_by_contact[participant.contact.contact].append(participant) + + for contact_email, participants in participants_by_contact.items(): + message = render_to_string('stage2/results_teacher.txt', dict(participants=participants)) + self.send_message(message, subject, contact_email) + + self.sum_up() + + def sum_up(self): + self.stdout.write('sent: %s, failed: %s' % (self.sent, self.failed)) + + def send_message(self, message, subject, email): + self.stdout.write('>>> sending results to %s' % email) + try: + 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) diff --git a/stage2/templates/stage2/results_student_failed.txt b/stage2/templates/stage2/results_student_failed.txt new file mode 100644 index 0000000..95a9f54 --- /dev/null +++ b/stage2/templates/stage2/results_student_failed.txt @@ -0,0 +1,13 @@ +{% load l10n %}Witaj, + +Informujemy, że wszystkie prace nadesłane w ramach II etapu Olimpiady Cyfrowej zostały ocenione. + +Liczba zdobytych przez Ciebie punktów to {% localize on %}{{ final_result|floatformat:2 }}{% endlocalize %}. + +Niestety, ten wynik nie uprawnia Cię do wzięcia udziału w zawodach III stopnia. Liczba punktów, która uprawnia do wzięcia udziału w finale to 55. Zachęcamy do zgłębiania wiedzy za zakresu edukacji cyfrowej i medialnej oraz wzięcia udziału w kolejnej edycji Olimpiady. + +W razie jakichkolwiek pytań prosimy o kontakt. + +Pozdrawiamy, +Zespół Olimpiady Cyfrowej +fundacja Nowoczesna Polsk diff --git a/stage2/templates/stage2/results_student_passed.txt b/stage2/templates/stage2/results_student_passed.txt new file mode 100644 index 0000000..5a44dde --- /dev/null +++ b/stage2/templates/stage2/results_student_passed.txt @@ -0,0 +1,13 @@ +{% load l10n %}Witaj, + +Informujemy, że wszystkie prace nadesłane w ramach II etapu Olimpiady Cyfrowej zostały ocenione. + +Liczba zdobytych przez Ciebie punktów to {% localize on %}{{ final_result|floatformat:2 }}{% endlocalize %}. + +Wynik ten uprawnia Cię do wzięcia udziału zawodach III stopnia. Serdecznie gratulujemy! Zawody finałowe odbędą się w 21 kwietnia w Warszawie. Niebawem prześlemy Ci szczegółowe informacje na ich temat. + +W razie jakichkolwiek pytań prosimy o kontakt. + +Pozdrawiamy, +Zespół Olimpiady Cyfrowej +fundacja Nowoczesna Polska diff --git a/stage2/templates/stage2/results_teacher.txt b/stage2/templates/stage2/results_teacher.txt new file mode 100644 index 0000000..b1f381d --- /dev/null +++ b/stage2/templates/stage2/results_teacher.txt @@ -0,0 +1,18 @@ +Dzień dobry, + +Informujemy, że wszystkie prace nadesłane w ramach II etapu Olimpiady Cyfrowej zostały ocenione. + +Poniżej znajdują się wyniki uzyskane przez zgłoszonych przez Panią/Pana uczniów i uczennice, którzy przesłali komplet rozwiązań. Liczba punktów, która uprawnia do wzięcia udziału w zawodach finałowych to 55. Gratulujemy tym, którym się to udało. Zawody finałowe odbędą się 21 kwietnia. Jeśli Pania/Pana uczniowie i uczennice awansowali do finału, niebawem otrzyma Pani/Pan szczegółowe informacje na ten temat. + +Wyniki uzyskane przez Pani/Pana podopiecznych: + +{% for participant in participants %}{{participant.first_name.strip}} {{participant.last_name.strip}}: {{participant.score|floatformat:2}} +{% endfor %} + +Informacje o wynikach zostały przesłane również Uczestnikom i Uczestniczkom. Prosimy upewnić się, że wszyscy otrzymali wiadomość. Jeśli jednak do nich nie dotarła, prosimy o podanie danych kontaktowych tych osób (imię i nazwisko, adres e-mail). + +W razie jakichkolwiek pytań prosimy o kontakt. + +Pozdrawiamy, +Zespół Olimpiady Cyfrowej +fundacja Nowoczesna Polska