forked from matfystutor/web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_study.py
52 lines (39 loc) · 1.36 KB
/
set_study.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
Set the 'study' field of TutorProfile objects
based on the rusclass of associated Rus objects.
Mathias Rav, February 2015
"""
from __future__ import print_function, unicode_literals
import os
import sys
import datetime
import subprocess
import collections
import codecs
sys.stdin = codecs.getreader('utf8')(sys.stdin)
sys.stdout = codecs.getwriter('utf8')(sys.stdout)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mftutor.settings'
import django.db.utils
from django.template import Template, Context
from django.template.loader import get_template
from django.core.mail import EmailMessage, EmailMultiAlternatives
from django.core.mail import get_connection
from mftutor.tutor.models import *
YEAR = 2015
tutors = TutorProfile.objects.filter(tutor__year__exact=YEAR, study='')
rus = list(Rus.objects.filter(profile__in=tutors).order_by('-year'))
assignments = []
for tutor in tutors:
r = next(x for x in rus if x.profile == tutor)
rusclass = r.rusclass.internal_name
study = re.sub(r' *[0-9]*$', '', rusclass)
assignments.append((study, tutor))
assignments = sorted(assignments)
if assignments:
for study, tutor in assignments:
print("%s %s" % (study, tutor.name))
print("Making the above assignments. Enter to proceed, or Ctrl-C to cancel.")
sys.stdin.read(1)
for study, tutor in assignments:
tutor.study = study
tutor.save()