X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/113c2e1bd6bb3f07fee917571a4f0f1b187c9807..b2579d9bb692cf293f8dea475103c60b286980b0:/wtem/management/commands/wtem_email_teachers.py diff --git a/wtem/management/commands/wtem_email_teachers.py b/wtem/management/commands/wtem_email_teachers.py index 40773f0..b2f1314 100644 --- a/wtem/management/commands/wtem_email_teachers.py +++ b/wtem/management/commands/wtem_email_teachers.py @@ -12,17 +12,21 @@ class Command(BaseCommand): sent = 0 failed = 0 - query = Contact.objects.filter(form_tag='olimpiada').order_by('contact').distinct('contact') + contacts = Contact.objects.filter(form_tag='olimpiada').exclude(contact=None).order_by('contact')\ + .distinct('contact') template_name = args[0] + emails = args[1:] + if emails: + contacts = contacts.filter(contact__in=emails) message = render_to_string('wtem/' + template_name + '.txt') subject = render_to_string('wtem/' + template_name + '_subject.txt') answer = raw_input( - 'Send the following to %d teachers with subject "%s"\n\n %s\n\n?' % - (query.count(), subject.encode('utf8'), message.encode('utf8'))) + 'Send the following to %d teachers with subject "%s"\n\n%s\n\n?' % + (contacts.count(), subject.encode('utf8'), message.encode('utf8'))) if answer == 'yes': - for contact in query: + for contact in contacts: try: self.send_message(message, subject, contact.contact) except Exception as e: