X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/130e1c7f8c43261d0e85e5ff9a354f037bb7cd24..7095c251b3ed9450375c82a7f465e2db201fe841:/wtem/management/commands/wtem_email_teachers.py?ds=inline diff --git a/wtem/management/commands/wtem_email_teachers.py b/wtem/management/commands/wtem_email_teachers.py index e0986f8..c8e95c3 100644 --- a/wtem/management/commands/wtem_email_teachers.py +++ b/wtem/management/commands/wtem_email_teachers.py @@ -1,14 +1,10 @@ # -*- coding: utf-8 -*- -import sys -from optparse import make_option - -from django.core.management.base import BaseCommand, CommandError -from django.conf import settings -from wtem.management.commands import send_mail +from django.core.management.base import BaseCommand from django.template.loader import render_to_string from contact.models import Contact +from wtem.management.commands import send_mail class Command(BaseCommand): @@ -16,16 +12,20 @@ class Command(BaseCommand): sent = 0 failed = 0 - query = Contact.objects.filter(form_tag = 'wtem').order_by('contact').distinct('contact') + contacts = Contact.objects.filter(form_tag='olimpiada').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'))) + answer = raw_input( + '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: @@ -39,9 +39,5 @@ class Command(BaseCommand): def send_message(self, message, subject, email): self.stdout.write('>>> sending to %s' % email) - send_mail( - subject = subject, - body = message, - to = [email] - ) + send_mail(subject=subject, body=message, to=[email])