def post(self, data, check, mutator): """See base.post for specification.""" profile_key = ndb.Key.from_old_key(data.url_project.parent_key()) # get type of survey based on submitted form name survey_type = _getSurveyType(data.POST) survey_key = project_survey_logic.constructEvaluationKey( data.program.key(), survey_type) # check if the survey exists if not db.get(survey_key): raise exception.BadRequest(message='Survey of type %s not found.' % survey_type) # try setting a personal extension form = PersonalExtensionForm(data=data.POST) result = _setPersonalExtension(profile_key, survey_key, form) if result: # redirect to somewhere url = links.LINKER.userId(data.url_ndb_profile.key, data.url_project.key().id(), urls.UrlNames.PROJECT_MANAGE_ADMIN) # TODO(daniel): append GET parameter in a better way url = url + '?validated' return http.HttpResponseRedirect(url) else: # TODO(nathaniel): problematic self-use. return self.get(data, check, mutator)
def post(self, data, check, mutator): """See base.post for specification.""" profile_key = ndb.Key.from_old_key(data.url_project.parent_key()) # get type of survey based on submitted form name survey_type = _getSurveyType(data.POST) survey_key = project_survey_logic.constructEvaluationKey( data.program.key(), survey_type) # check if the survey exists if not db.get(survey_key): raise exception.BadRequest(message='Survey of type %s not found.' % survey_type) # try setting a personal extension form = PersonalExtensionForm(data=data.POST) result = _setPersonalExtension(profile_key, survey_key, form) if result: # redirect to somewhere url = links.LINKER.userId( data.url_ndb_profile.key, data.url_project.key().id(), urls.UrlNames.PROJECT_MANAGE_ADMIN) # TODO(daniel): append GET parameter in a better way url = url + '?validated' return http.HttpResponseRedirect(url) else: # TODO(nathaniel): problematic self-use. return self.get(data, check, mutator)
def testGetFinalEvaluationKey(self): """Tests that correct final evaluation key is returned.""" program = program_utils.seedGSoCProgram() actual_key = project_survey_logic.constructEvaluationKey( program.key(), project_survey_model.FINAL_EVAL) expected_key = db.Key.from_path( project_survey_model.ProjectSurvey.kind(), 'gsoc_program/%s/%s' % ( program.key().name(), project_survey_model.FINAL_EVAL)) self.assertEqual(actual_key, expected_key)
def testUnknownSurveyType(self): """Tests that error is raised when survey type is not supported.""" program = program_utils.seedGSoCProgram() with self.assertRaises(ValueError): project_survey_logic.constructEvaluationKey(program.key(), 'unknown')