X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/6e2ebe7bbbabddca6929ac2e02c5b8d72065db3a..b5e102c4572593e7bd90b64b82715dd60b9ac1c2:/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 205e444..97a98eb 100644 --- a/wtem/management/commands/wtem_send_results_csv.py +++ b/wtem/management/commands/wtem_send_results_csv.py @@ -51,24 +51,25 @@ class Command(BaseCommand): def handle_to_students(self, *args, **options): self.stdout.write('>>> Sending results to students') - subject = 'Wyniki I etapu Wielkiego Turnieju Edukacji Medialnej' + subject = 'Wyniki II etapu Wielkiego Turnieju Edukacji Medialnej' - for result in self.results: - if options['only_to'] and result[1] != options['only_to']: + for email, last_name, first_name, final_result in self.results: + if options['only_to'] and email != options['only_to']: continue - final_result = result[4] - if result[5] != 'TAK': + if final_result == 'dyskwalifikacja': + template = 'results_student_disqualified.txt' + elif float(final_result) < minimum: template = 'results_student_failed.txt' else: template = 'results_student_passed.txt' message = render_to_string('wtem/' + template, dict(final_result=final_result)) - self.send_message(message, subject, result[1]) + self.send_message(message, subject, email) self.sum_up() def handle_to_teachers(self, *args, **options): self.stdout.write('>>> Sending results to teachers') - subject = 'Wyniki I etapu Wielkiego Turnieju Edukacji Medialnej' + subject = 'Wyniki II etapu Wielkiego Turnieju Edukacji Medialnej' submissions_by_contact = dict() @@ -80,13 +81,16 @@ class Command(BaseCommand): except InvalidOperation: return Decimal(0) - for result in sorted(self.results, key=lambda r: dec_or_0(r[4]), reverse=True): - if options['only_to'] and result[3] != options['only_to']: + sorted_results = sorted(self.results, key=lambda r: dec_or_0(r[3]), reverse=True) + for email, last_name, first_name, final_result in sorted_results: + submission = Submission.objects.get(email=email) + teacher_email = submission.contact.contact + if options['only_to'] and teacher_email != options['only_to']: continue - submissions_by_contact.setdefault(result[3], []).append({ - 'first_name': result[0].split()[0], - 'last_name': result[0].split()[1], - 'final_result': result[4], + submissions_by_contact.setdefault(teacher_email, []).append({ + 'first_name': first_name, + 'last_name': last_name, + 'final_result': final_result, }) for email, submissions in submissions_by_contact.items():