73 survey_key = post_dict.get('survey_key') |
75 survey_key = post_dict.get('survey_key') |
74 survey_type = post_dict.get('survey_type') |
76 survey_type = post_dict.get('survey_type') |
75 |
77 |
76 if not (program_key and survey_key and survey_type): |
78 if not (program_key and survey_key and survey_type): |
77 # invalid task data, log and return OK |
79 # invalid task data, log and return OK |
78 return logErrorAndReturnOK( |
80 return error_handler.logErrorAndReturnOK( |
79 'Invalid sendRemindersForProjectSurvey data: %s' % post_dict) |
81 'Invalid sendRemindersForProjectSurvey data: %s' % post_dict) |
80 |
82 |
81 # get the program for the given keyname |
83 # get the program for the given keyname |
82 program_entity = program_logic.getFromKeyName(program_key) |
84 program_entity = program_logic.getFromKeyName(program_key) |
83 |
85 |
84 if not program_entity: |
86 if not program_entity: |
85 # invalid program specified, log and return OK |
87 # invalid program specified, log and return OK |
86 return logErrorAndReturnOK('Invalid program specified: %s' % program_key) |
88 return error_handler.logErrorAndReturnOK( |
|
89 'Invalid program specified: %s' % program_key) |
87 |
90 |
88 # check and retrieve the project_key that has been done last |
91 # check and retrieve the project_key that has been done last |
89 if 'project_key' in post_dict: |
92 if 'project_key' in post_dict: |
90 project_start_key = post_dict['project_key'] |
93 project_start_key = post_dict['project_key'] |
91 else: |
94 else: |
99 # retrieve the last project that was done |
102 # retrieve the last project that was done |
100 project_start = student_project_logic.getFromKeyName(project_start_key) |
103 project_start = student_project_logic.getFromKeyName(project_start_key) |
101 |
104 |
102 if not project_start: |
105 if not project_start: |
103 # invalid starting project key specified, log and return OK |
106 # invalid starting project key specified, log and return OK |
104 return logErrorAndReturnOK('Invalid Student Project Key specified: %s' %( |
107 return error_handler.logErrorAndReturnOK( |
105 project_start_key)) |
108 'Invalid Student Project Key specified: %s' %(project_start_key)) |
106 |
109 |
107 fields['__key__ >'] = project_start.key() |
110 fields['__key__ >'] = project_start.key() |
108 |
111 |
109 project_entities = student_project_logic.getForFields(fields, |
112 project_entities = student_project_logic.getForFields(fields, |
110 limit=batch_size) |
113 limit=batch_size) |
167 survey_key = post_dict.get('survey_key') |
170 survey_key = post_dict.get('survey_key') |
168 survey_type = post_dict.get('survey_type') |
171 survey_type = post_dict.get('survey_type') |
169 |
172 |
170 if not (project_key and survey_key and survey_type): |
173 if not (project_key and survey_key and survey_type): |
171 # invalid task data, log and return OK |
174 # invalid task data, log and return OK |
172 return logErrorAndReturnOK( |
175 return error_handler.logErrorAndReturnOK( |
173 'Invalid sendSurveyReminderForProject data: %s' % post_dict) |
176 'Invalid sendSurveyReminderForProject data: %s' % post_dict) |
174 |
177 |
175 # set logic depending on survey type specified in POST |
178 # set logic depending on survey type specified in POST |
176 if survey_type == 'project': |
179 if survey_type == 'project': |
177 survey_logic = project_logic |
180 survey_logic = project_logic |
181 # retrieve the project and survey |
184 # retrieve the project and survey |
182 student_project = student_project_logic.getFromKeyName(project_key) |
185 student_project = student_project_logic.getFromKeyName(project_key) |
183 |
186 |
184 if not student_project: |
187 if not student_project: |
185 # no existing project found, log and return OK |
188 # no existing project found, log and return OK |
186 return logErrorAndReturnOK('Invalid project specified %s:' % project_key) |
189 return error_handler.logErrorAndReturnOK( |
|
190 'Invalid project specified %s:' % project_key) |
187 |
191 |
188 survey = survey_logic.getFromKeyName(survey_key) |
192 survey = survey_logic.getFromKeyName(survey_key) |
189 |
193 |
190 if not survey: |
194 if not survey: |
191 # no existing survey found, log and return OK |
195 # no existing survey found, log and return OK |
192 return logErrorAndReturnOK('Invalid survey specified %s:' % survey_key) |
196 return error_handler.logErrorAndReturnOK( |
|
197 'Invalid survey specified %s:' % survey_key) |
193 |
198 |
194 # try to retrieve an existing record |
199 # try to retrieve an existing record |
195 record_logic = survey_logic.getRecordLogic() |
200 record_logic = survey_logic.getRecordLogic() |
196 |
201 |
197 fields = {'project': student_project, |
202 fields = {'project': student_project, |
256 # send out the email |
261 # send out the email |
257 mail_dispatcher.sendMailFromTemplate(mail_template, mail_context) |
262 mail_dispatcher.sendMailFromTemplate(mail_template, mail_context) |
258 |
263 |
259 # return OK |
264 # return OK |
260 return http.HttpResponse() |
265 return http.HttpResponse() |
261 |
|
262 |
|
263 def logErrorAndReturnOK(error_msg='Error found in Survey Task'): |
|
264 """Logs the given error message and returns a HTTP OK response. |
|
265 |
|
266 Args: |
|
267 error_msg: Error message to log |
|
268 """ |
|
269 logging.error(error_msg) |
|
270 return http.HttpResponse() |
|