author | Lennard de Rijk <ljvderijk@gmail.com> |
Sat, 18 Apr 2009 21:26:13 +0000 | |
changeset 2225 | c6a0f935504c |
parent 2223 | 7b8b812aa146 |
child 2226 | 6159450c4767 |
permissions | -rw-r--r-- |
2223
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
1 |
#!/usr/bin/python2.5 |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
2 |
# |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
3 |
# Copyright 2009 the Melange authors. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
4 |
# |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
5 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
6 |
# you may not use this file except in compliance with the License. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
7 |
# You may obtain a copy of the License at |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
8 |
# |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
10 |
# |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
11 |
# Unless required by applicable law or agreed to in writing, software |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
14 |
# See the License for the specific language governing permissions and |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
15 |
# limitations under the License. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
16 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
17 |
"""Cron job handler for Student Proposal mailing. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
18 |
""" |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
19 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
20 |
__authors__ = [ |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
21 |
'"Lennard de Rijk" <ljvderijk@gmail.com>', |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
22 |
] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
23 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
24 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
25 |
import logging |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
26 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
27 |
from soc.logic.models.job import logic as job_logic |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
28 |
from soc.logic.models.priority_group import logic as priority_logic |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
29 |
from soc.logic.models.program import logic as program_logic |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
30 |
from soc.logic.models.student import logic as student_logic |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
31 |
from soc.logic.models.student_proposal import logic as proposal_logic |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
32 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
33 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
34 |
# amount of students to create jobs for before updating |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
35 |
DEF_STUDENT_STEP_SIZE = 10 |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
36 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
37 |
# property text_data for a sendStudentProposalMail Job |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
38 |
DEF_STUDENT_PROPOSAL_MAIL_TEXT_DATA_FMT = '%s/proposal_mail' |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
39 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
40 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
41 |
def setupStudentProposalMailing(job_entity): |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
42 |
"""Job that setup jobs that will mail students if they have been accepted in |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
43 |
a program with a GSoC-like workflow. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
44 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
45 |
Args: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
46 |
job_entity: a Job entity with key_data set to |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
47 |
[program, last_completed_student] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
48 |
""" |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
49 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
50 |
from soc.cron.job import FatalJobError |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
51 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
52 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
53 |
# retrieve the data we need to continue our work |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
54 |
key_data = job_entity.key_data |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
55 |
program_key = key_data[0] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
56 |
program_keyname = program_key.name() |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
57 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
58 |
program_entity = program_logic.getFromKeyName(program_keyname) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
59 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
60 |
if not program_entity: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
61 |
raise FatalJobError('The program with key %s could not be found' % ( |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
62 |
program_keyname)) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
63 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
64 |
student_fields = {'scope': program_entity} |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
65 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
66 |
if len(key_data) >= 2: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
67 |
# start where we left off |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
68 |
student_fields['__key__ >'] = key_data[1] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
69 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
70 |
students = student_logic.getForFields(student_fields, |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
71 |
limit=DEF_STUDENT_STEP_SIZE) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
72 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
73 |
# set the default fields for the jobs we are going to create |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
74 |
priority_group = priority_logic.getGroup(priority_logic.EMAIL) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
75 |
job_fields = { |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
76 |
'priority_group': priority_group, |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
77 |
'task_name': 'sendStudentProposalMail'} |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
78 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
79 |
job_query_fields = job_fields.copy() |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
80 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
81 |
while students: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
82 |
# for each student create a mailing job |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
83 |
for student in students: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
84 |
text_data = DEF_STUDENT_PROPOSAL_MAIL_TEXT_DATA_FMT % ( |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
85 |
student.key().name()) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
86 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
87 |
job_query_fields['text_data'] = text_data |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
88 |
mail_job = job_logic.getForFields(job_query_fields, unique=True) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
89 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
90 |
if not mail_job: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
91 |
# this student did not receive mail yet |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
92 |
job_fields['text_data'] = text_data |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
93 |
job_fields['key_data'] = [student.key()] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
94 |
job_logic.updateOrCreateFromFields(job_fields) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
95 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
96 |
# update our own job |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
97 |
last_student_key = students[-1].key() |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
98 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
99 |
if len(key_data) >= 2: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
100 |
key_data[1] = last_student_key |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
101 |
else: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
102 |
key_data.append(last_student_key) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
103 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
104 |
updated_job_fields = {'key_data': key_data} |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
105 |
job_logic.updateEntityProperties(job_entity, updated_job_fields) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
106 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
107 |
# rinse and repeat |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
108 |
student_fields['__key__ >'] = last_student_key |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
109 |
students = student_logic.getForFields(student_fields, |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
110 |
limit=DEF_STUDENT_STEP_SIZE) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
111 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
112 |
# we are finished |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
113 |
return |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
114 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
115 |
def sendStudentProposalMail(job_entity): |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
116 |
"""Job that will send out an email to a student that sent in a proposal |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
117 |
that either got accepted or rejected. |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
118 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
119 |
Args: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
120 |
job_entity: a Job entity with key_data set to [student_key] |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
121 |
""" |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
122 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
123 |
from soc.cron.job import FatalJobError |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
124 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
125 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
126 |
student_keyname = job_entity.key_data[0].name() |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
127 |
student_entity = student_logic.getFromKeyName(student_keyname) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
128 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
129 |
if not student_entity: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
130 |
raise FatalJobError('The student with keyname %s does not exist!' % ( |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
131 |
student_keyname)) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
132 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
133 |
# only students who have sent in a proposal will be mailed |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
134 |
fields = {'scope': student_entity} |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
135 |
proposal = proposal_logic.getForFields(fields, unique=True) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
136 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
137 |
if proposal: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
138 |
# check if the student has an accepted proposal |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
139 |
fields['status'] = 'accepted' |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
140 |
accepted_proposal = proposal_logic.getForFields(fields, unique=True) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
141 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
142 |
# TODO(ljvderijk) replace with real mail sending |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
143 |
if accepted_proposal: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
144 |
logging.info('Sending acceptance mail to %s' % (student_entity.name())) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
145 |
else: |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
146 |
logging.info('Sending rejectance mail to %s' % (student_entity.name())) |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
147 |
|
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
148 |
# we are done here |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
149 |
return |
7b8b812aa146
Added Student Proposal Mailer module for mailing students who are accepted/rejected into the program.
Lennard de Rijk <ljvderijk@gmail.com>
parents:
diff
changeset
|
150 |