fnp
/
edumed.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
update send-results command and templates
[edumed.git]
/
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
f3f9917
..
f4748c6
100644
(file)
--- a/
wtem/management/commands/wtem_send_results.py
+++ b/
wtem/management/commands/wtem_send_results.py
@@
-2,6
+2,7
@@
from optparse import make_option
from optparse import make_option
+from collections import defaultdict
from django.core.management.base import BaseCommand
from wtem.management.commands import send_mail
from django.utils import translation
from django.core.management.base import BaseCommand
from wtem.management.commands import send_mail
from django.utils import translation
@@
-11,9
+12,9
@@
from wtem.models import Submission
def get_submissions():
def get_submissions():
- return sorted(Submission.objects.exclude(answers=None)
.all()
, key=lambda s: -s.final_result)
+ return sorted(Submission.objects.exclude(answers=None), key=lambda s: -s.final_result)
-minimum =
34
+minimum =
63.06
class Command(BaseCommand):
class Command(BaseCommand):
@@
-37,14
+38,22
@@
class Command(BaseCommand):
dest='only_to',
default=None,
help='Send email only to one address'),
dest='only_to',
default=None,
help='Send email only to one address'),
+ make_option(
+ '--dummy',
+ action='store_true',
+ dest='dummy',
+ default=False,
+ help='Print emails instead of sending them'),
)
def __init__(self):
super(Command, self).__init__()
self.sent = self.failed = None
)
def __init__(self):
super(Command, self).__init__()
self.sent = self.failed = None
+ self.dummy = None
def handle(self, *args, **options):
translation.activate('pl')
def handle(self, *args, **options):
translation.activate('pl')
+ self.dummy = options['dummy']
for target in ['to_teachers', 'to_students']:
if options[target]:
self.sent = 0
for target in ['to_teachers', 'to_students']:
if options[target]:
self.sent = 0
@@
-63,7
+72,7
@@
class Command(BaseCommand):
template = 'results_student_failed.txt'
else:
template = 'results_student_passed.txt'
template = 'results_student_failed.txt'
else:
template = 'results_student_passed.txt'
- message = render_to_string('wtem/' + template, dict(final_result=
submission.final_result
))
+ message = render_to_string('wtem/' + template, dict(final_result=
round(submission.final_result, 2)
))
self.send_message(message, subject, submission.email)
self.sum_up()
self.send_message(message, subject, submission.email)
self.sum_up()
@@
-72,12
+81,12
@@
class Command(BaseCommand):
self.stdout.write('>>> Sending results to teachers')
subject = 'Wyniki I etapu Olimpiady Cyfrowej'
self.stdout.write('>>> Sending results to teachers')
subject = 'Wyniki I etapu Olimpiady Cyfrowej'
- submissions_by_contact = d
ict(
)
+ submissions_by_contact = d
efaultdict(list
)
for submission in get_submissions():
if options['only_to'] and submission.contact.contact != options['only_to']:
continue
for submission in get_submissions():
if options['only_to'] and submission.contact.contact != options['only_to']:
continue
- submissions_by_contact
.setdefault(submission.contact.contact, [])
.append(submission)
+ submissions_by_contact
[submission.contact.contact]
.append(submission)
for contact_email, submissions in submissions_by_contact.items():
message = render_to_string('wtem/results_teacher.txt', dict(submissions=submissions))
for contact_email, submissions in submissions_by_contact.items():
message = render_to_string('wtem/results_teacher.txt', dict(submissions=submissions))
@@
-90,6
+99,10
@@
class Command(BaseCommand):
def send_message(self, message, subject, email):
self.stdout.write('>>> sending results to %s' % email)
def send_message(self, message, subject, email):
self.stdout.write('>>> sending results to %s' % email)
+ if self.dummy:
+ self.stdout.write(message)
+ self.sent += 1
+ return
try:
send_mail(subject=subject, body=message, to=[email])
except BaseException, e:
try:
send_mail(subject=subject, body=message, to=[email])
except BaseException, e: