X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/a0e5579f9eba72add85eb75c6267bdf3c1313432..3ca90d4aed87ed8b39c4984a290de6a3b898a7bd:/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 ef593e7..f3f9917 100644 --- a/wtem/management/commands/wtem_send_results.py +++ b/wtem/management/commands/wtem_send_results.py @@ -7,14 +7,13 @@ from wtem.management.commands import send_mail from django.utils import translation from django.template.loader import render_to_string -from contact.models import Contact from wtem.models import Submission def get_submissions(): return sorted(Submission.objects.exclude(answers=None).all(), key=lambda s: -s.final_result) -minimum = 52 +minimum = 34 class Command(BaseCommand): @@ -37,9 +36,13 @@ class Command(BaseCommand): action='store', dest='only_to', default=None, - help='Send emails only to listed addresses'), + 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']: @@ -74,12 +77,11 @@ class Command(BaseCommand): 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) + submissions_by_contact.setdefault(submission.contact.contact, []).append(submission) - for contact_id, submissions in submissions_by_contact.items(): - contact = Contact.objects.get(id=contact_id) + for contact_email, submissions in submissions_by_contact.items(): message = render_to_string('wtem/results_teacher.txt', dict(submissions=submissions)) - self.send_message(message, subject, contact.contact) + self.send_message(message, subject, contact_email) self.sum_up()