def update(request, application_id=None): """ Sociological survey of an applicant. :param request :param application_id """ applicant = mdl.applicant.find_by_user(request.user) if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) next_tab = navigation.SOCIOLOGICAL_SURVEY_TAB sociological_survey = sociological_survey_mdl.find_by_applicant(applicant) if request.method == "POST": sociological_form = SociologicalSurveyForm(request.POST) if sociological_form.is_valid(): sociological_form.save(applicant=applicant) sociological_survey = sociological_survey_mdl.find_by_applicant( applicant) following_tab = navigation.get_following_tab( request, 'sociological', application) if following_tab: return following_tab else: sociological_form = SociologicalSurveyForm( instance=sociological_survey) elif sociological_survey: sociological_form = SociologicalSurveyForm( instance=sociological_survey) else: sociological_form = SociologicalSurveyForm() data = { 'tab_active': next_tab, 'application': application, 'applications': mdl.application.find_by_user(request.user), 'sociological_form': sociological_form, 'professions': mdl.profession.find_by_adoc(False), 'sociological_survey': sociological_survey } data.update( demande_validation.get_validation_status(application, applicant)) return render(request, "admission_home.html", data)
def update(request, application_id=None): """ Sociological survey of an applicant. :param request :param application_id """ applicant = mdl.applicant.find_by_user(request.user) if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) next_tab = navigation.SOCIOLOGICAL_SURVEY_TAB sociological_survey = sociological_survey_mdl.find_by_applicant(applicant) if request.method == "POST": sociological_form = SociologicalSurveyForm(request.POST) if sociological_form.is_valid(): sociological_form.save(applicant=applicant) sociological_survey = sociological_survey_mdl.find_by_applicant(applicant) following_tab = navigation.get_following_tab(request, 'sociological', application) if following_tab: return following_tab else: sociological_form = SociologicalSurveyForm(instance=sociological_survey) elif sociological_survey: sociological_form = SociologicalSurveyForm(instance=sociological_survey) else: sociological_form = SociologicalSurveyForm() data = { 'tab_active': next_tab, 'application': application, 'applications': mdl.application.find_by_user(request.user), 'sociological_form': sociological_form, 'professions': mdl.profession.find_by_adoc(False), 'sociological_survey': sociological_survey } data.update(demande_validation.get_validation_status(application, applicant)) return render(request, "admission_home.html", data)
def test_clean_form_from_view(self): given_conjoint_profession_name = "Nez" given_mother_profession_name = "Obstétricienne" given_father_profession_name = "Barman" given_student_profession_name = 'Pompier' given_maternal_grandfather_profession_name = 'Mineur' given_paternal_grandfather_profession_name = 'Cordonnier' form = init_form(data={ 'applicant': self.applicant.id, 'number_brothers_sisters': 2, 'student_profession_not_found': True, 'student_profession_other_name': given_student_profession_name, 'student_professional_activity': professional_activity_enum.FULL_TIME, 'conjoint_profession_not_found': True, 'conjoint_profession_other_name': given_conjoint_profession_name, 'conjoint_professional_activity': professional_activity_enum.FULL_TIME, 'father_profession_not_found': True, 'father_profession_other_name': given_father_profession_name, 'mother_profession_not_found': True, 'mother_profession_other_name': given_mother_profession_name, 'maternal_grandfather_profession_not_found': True, 'maternal_grandfather_profession_other_name': given_maternal_grandfather_profession_name, 'paternal_grandfather_profession_not_found': True, 'paternal_grandfather_profession_other_name': given_paternal_grandfather_profession_name, }) self.assertTrue(form.is_valid(), str(form.errors)) form.save(applicant=self.applicant) sociological_survey = mdl_sociological_survey.find_by_applicant(applicant=self.applicant) self.assertTrue(sociological_survey.student_profession.adhoc) self.assertTrue(sociological_survey.student_profession.name == given_student_profession_name) self.assertTrue(sociological_survey.conjoint_profession.adhoc) self.assertTrue(sociological_survey.conjoint_profession.name == given_conjoint_profession_name) self.assertTrue(sociological_survey.mother_profession.adhoc) self.assertTrue(sociological_survey.mother_profession.name == given_mother_profession_name) self.assertTrue(sociological_survey.father_profession.adhoc) self.assertTrue(sociological_survey.father_profession.name == given_father_profession_name) self.assertTrue(sociological_survey.paternal_grandfather_profession.adhoc) self.assertTrue(sociological_survey.paternal_grandfather_profession.name == given_paternal_grandfather_profession_name) self.assertTrue(sociological_survey.maternal_grandfather_profession.adhoc) self.assertTrue(sociological_survey.maternal_grandfather_profession.name == given_maternal_grandfather_profession_name)