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 accounting_update(request, application_id=None): next_tab = navigation.ACCOUNTING_TAB academic_yr = mdl_base.academic_year.current_academic_year() previous_academic_year = mdl_base.academic_year.find_by_year(academic_yr.year - 1) sport_affiliation_amount = 0 culture_affiliation_amount = 0 solidary_affiliation_amount = 0 accounting_form = None if request.method == 'POST': accounting_form = AccountingForm(data=request.POST) if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) try: if application.offer_year and application.applicant: application.save() except: pass following_tab = navigation.get_following_tab(request, 'accounting', application) if following_tab: return following_tab data = { "academic_year": academic_yr, "previous_academic_year": previous_academic_year, "sport_affiliation_amount": sport_affiliation_amount, "culture_affiliation_amount": culture_affiliation_amount, "solidary_affiliation_amount": solidary_affiliation_amount, "application": application, "form": accounting_form, "debts_check": debts_check(application), "reduction_possible": reduction_possible(application), "third_cycle": third_cycle(application), "tab_active": next_tab, "applications": mdl.application.find_by_user(request.user), } applicant = mdl.applicant.find_by_user(request.user) 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 save(request, application_id=None): save_step = False duplicate = False duplicate_year_origin = None validation_messages = {} if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) key = 'bt_duplicate_' for k, v in request.POST.items(): if k.startswith(key): duplicate = True duplicate_year_origin = int(k.replace(key, '')) break if duplicate: pass else: save_step = True message_success = None # Get the data in bd for dropdown list local_universities_french = mdl_reference.education_institution \ .find_by_institution_type_national_community(education_institution_type.UNIVERSITY, national_cmunity_type.FRENCH, False) local_universities_dutch = mdl_reference.education_institution \ .find_by_institution_type_national_community(education_institution_type.UNIVERSITY, national_cmunity_type.DUTCH, False) universities_cities = [] universities = [] if save_step or duplicate: is_valid, validation_messages, curricula, universities_cities, universities, duplication_possible \ = validate_fields_form(request, duplicate_year_origin) is_valid = True # a modifier avec issue 180 if is_valid: message_success = _('msg_info_saved') for curriculum in curricula: curriculum.save() following_tab = navigation.get_following_tab(request, 'curriculum', application) if following_tab: return following_tab else: return render(request, "admission_home.html", {"curricula": curricula, "local_universities_french": local_universities_french, "local_universities_dutch": local_universities_dutch, "domains": mdl_reference.domain.find_current_domains(), "subdomains": mdl_reference.domain.find_parent_domains(), "grade_types": mdl_reference.grade_type.find_all(), "validation_messages": validation_messages, "message_success": message_success, "universities_cities": universities_cities, "universities": universities, "languages": mdl_reference.language.find_languages(), "current_academic_year": mdl_base.academic_year.current_academic_year(), "tab_active": navigation.CURRICULUM_TAB, "application": application}) # Get the data in bd applicant = mdl.applicant.find_by_user(request.user) first_academic_year_for_cv = None curricula = [] # find existing cv secondary_education = mdl.secondary_education.find_by_person(applicant) if secondary_education: if secondary_education.academic_year: first_academic_year_for_cv = secondary_education.academic_year + 1 current_academic_year = mdl_base.academic_year.current_academic_year().year year = first_academic_year_for_cv if year: while year < current_academic_year: curriculum = mdl.curriculum.find_by_person_year(applicant, year) if curriculum is None: # add cv empty cv's for the year if it's needed curriculum = mdl.curriculum.Curriculum() curriculum.person = applicant curriculum.academic_year = year curricula.append(curriculum) year += 1 return render(request, "admission_home.html", {"curricula": curricula, "local_universities_french": local_universities_french, "local_universities_dutch": local_universities_dutch, "domains": mdl_reference.domain.find_current_domains(), "subdomains": mdl_reference.domain.find_parent_domains(), "grade_types": mdl_reference.grade_type.find_all(), "universities_countries": mdl_reference.education_institution.find_countries(), "validation_messages": validation_messages, "message_success": message_success, "universities_cities": universities_cities, "universities": universities, "languages": mdl_reference.language.find_languages(), "current_academic_year": mdl_base.academic_year.current_academic_year(), "tab_active": navigation.CURRICULUM_TAB, "application": application})
def profile(request, application_id=None, message_success=None): message_info = None application = None assimilation_case = False if application_id: application = mdl.application.find_by_id(application_id) if request.method == 'POST': applicant_form = ApplicantForm(data=request.POST) applicant = mdl.applicant.find_by_user(request.user) person_legal_address = mdl.person_address.find_by_person_type( applicant, 'LEGAL') if person_legal_address is None: person_legal_address = mdl.person_address.PersonAddress() person_legal_address.person = applicant person_legal_address.type = 'LEGAL' if request.POST['last_name']: applicant.user.last_name = request.POST['last_name'] else: applicant.user.last_name = None if request.POST['first_name']: applicant.user.first_name = request.POST['first_name'] else: applicant.user.first_name = None if request.POST['middle_name']: applicant.middle_name = request.POST['middle_name'] else: applicant.middle_name = None if request.POST['birth_date']: try: applicant.birth_date = datetime.strptime( request.POST['birth_date'], '%d/%m/%Y') except ValueError: applicant.birth_date = None applicant_form.errors[ 'birth_date'] = "La date encodée('%s') semble incorrecte " % request.POST[ 'birth_date'] else: applicant.birth_date = None if request.POST['birth_place']: applicant.birth_place = request.POST['birth_place'] else: applicant.birth_place = None if request.POST.get('birth_country'): birth_country_id = request.POST['birth_country'] if birth_country_id and int(birth_country_id) >= 0: birth_country = mdl_ref.country.find_by_id(birth_country_id) else: birth_country = None applicant.birth_country = birth_country else: applicant.birth_country = None if request.POST.get('gender'): applicant.gender = request.POST['gender'] else: applicant.gender = None if request.POST['civil_status']: applicant.civil_status = request.POST['civil_status'] else: applicant.civil_status = None if request.POST['number_children']: applicant.number_children = request.POST['number_children'] else: applicant.number_children = None if request.POST['spouse_name']: applicant.spouse_name = request.POST['spouse_name'] else: applicant.spouse_name = None if request.POST.get( 'nationality') and not request.POST.get('nationality') == "-1": country_id = request.POST['nationality'] if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) else: country = None if country: if not country.european_union: assimilation_case = True applicant.nationality = country else: applicant.nationality = None if request.POST['national_id']: applicant.national_id = request.POST['national_id'] else: applicant.national_id = None if request.POST['id_card_number']: applicant.id_card_number = request.POST['id_card_number'] else: applicant.id_card_number = None if request.POST['passport_number']: applicant.passport_number = request.POST['passport_number'] else: applicant.passport_number = None if request.POST['legal_adr_street']: person_legal_address.street = request.POST['legal_adr_street'] else: person_legal_address.street = '' if request.POST['legal_adr_number']: person_legal_address.number = request.POST['legal_adr_number'] else: person_legal_address.number = '' if request.POST['legal_adr_complement']: person_legal_address.complement = request.POST[ 'legal_adr_complement'] else: person_legal_address.complement = None if request.POST['legal_adr_postal_code']: person_legal_address.postal_code = request.POST[ 'legal_adr_postal_code'] else: person_legal_address.postal_code = '' if request.POST['legal_adr_city']: person_legal_address.city = request.POST['legal_adr_city'] else: person_legal_address.city = '' if request.POST.get('legal_adr_country') and not request.POST.get( 'legal_adr_country') == "-1": country_id = request.POST['legal_adr_country'] country = None if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) person_legal_address.country = country else: applicant_form.errors['legal_adr_country'] = _('mandatory_field') if request.POST.get('same_contact_legal_addr') == "false": person_contact_address = mdl.person_address.find_by_person_type( applicant, 'CONTACT') if person_contact_address is None: person_contact_address = mdl.person_address.PersonAddress() person_contact_address.person = applicant person_contact_address.type = 'CONTACT' if request.POST['contact_adr_street']: person_contact_address.street = request.POST[ 'contact_adr_street'] else: person_contact_address.street = None if request.POST['contact_adr_number']: person_contact_address.number = request.POST[ 'contact_adr_number'] else: person_contact_address.number = None if request.POST['contact_adr_complement']: person_contact_address.complement = request.POST[ 'contact_adr_complement'] else: person_contact_address.complement = None if request.POST['contact_adr_postal_code']: person_contact_address.postal_code = request.POST[ 'contact_adr_postal_code'] else: person_contact_address.postal_code = None if request.POST['contact_adr_city']: person_contact_address.city = request.POST['contact_adr_city'] else: person_contact_address.city = None if request.POST['contact_adr_country']: country_id = request.POST['contact_adr_country'] country = None if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) if country: person_contact_address.country = country else: person_contact_address.country = None same_addresses = False person_contact_address.save() else: same_addresses = True person_contact_address = mdl.person_address.find_by_person_type( applicant, 'CONTACT') if person_contact_address: person_contact_address.delete() person_contact_address = None if request.POST['phone_mobile']: applicant.phone_mobile = request.POST['phone_mobile'] if request.POST['phone']: applicant.phone = request.POST['phone'] else: applicant.phone = None if request.POST['previous_enrollment'] == "true": if request.POST['registration_id']: applicant.registration_id = request.POST['registration_id'] else: applicant.registration_id = None if request.POST['last_academic_year']: applicant.last_academic_year = request.POST[ 'last_academic_year'] else: applicant.last_academic_year = None previous_enrollment = True else: applicant.registration_id = None applicant.last_academic_year = None previous_enrollment = False if assimilation_case: # verify if it exists one record per criteria default_criteria_list = assimilation_criteria_enum.ASSIMILATION_CRITERIA_CHOICES for criteria in default_criteria_list: crit = criteria[0] existing_crit = mdl.applicant_assimilation_criteria.find_first( applicant, crit) if existing_crit is None: applicant_assimilation_criteria = \ mdl.applicant_assimilation_criteria.ApplicantAssimilationCriteria() applicant_assimilation_criteria.criteria = crit applicant_assimilation_criteria.applicant = applicant applicant_assimilation_criteria.additional_criteria = None applicant_assimilation_criteria.selected = None applicant_assimilation_criteria.save() if application: application_assimilation_criteria = mdl.application_assimilation_criteria.find_first( application, crit) if application_assimilation_criteria is None: application_assimilation_criteria = \ mdl.application_assimilation_criteria.ApplicationAssimilationCriteria() application_assimilation_criteria.criteria = crit application_assimilation_criteria.application = application application_assimilation_criteria.additional_criteria = None application_assimilation_criteria.selected = None application_assimilation_criteria.save() for key in request.POST: if key[0:len(RADIO_NAME_ASSIMILATION_CRITERIA )] == RADIO_NAME_ASSIMILATION_CRITERIA: criteria_id = key[len(RADIO_NAME_ASSIMILATION_CRITERIA):] criteria_ref = assimilation_criteria_enum.find(criteria_id) criteria = criteria_ref[0] applicant_assimilation_criteria = mdl.applicant_assimilation_criteria.find_first( applicant, criteria) if applicant_assimilation_criteria is None: applicant_assimilation_criteria = mdl.applicant_assimilation_criteria\ .ApplicantAssimilationCriteria() applicant_assimilation_criteria.criteria = criteria applicant_assimilation_criteria.applicant = applicant if request.POST[key] == "true": if criteria: assimilation_basic_documents = assimilation_criteria_view.\ find_list_assimilation_basic_documents() list_document_type_needed = assimilation_criteria_view.\ get_list_documents_descriptions(criteria) list_document_type_needed.append( document_type.ID_CARD) if criteria == assimilation_criteria_enum.CRITERIA_5: if request.POST.get( "criteria_5" ) == assimilation_criteria_enum.CRITERIA_1: list_document_type_needed.extend([ document_type.RESIDENT_LONG_DURATION, document_type.ID_FOREIGN_UNLIMITED ]) if request.POST.get( "criteria_5" ) == assimilation_criteria_enum.CRITERIA_2: list_document_type_needed.extend([ document_type.ATTACHMENT_26, document_type.REFUGEE_CARD, document_type.FAMILY_COMPOSITION, document_type.BIRTH_CERTIFICATE, document_type.REFUGEE_CARD, document_type.RESIDENT_CERTIFICATE, document_type. FOREIGN_INSCRIPTION_CERTIFICATE, document_type. SUBSIDIARY_PROTECTION_DECISION, document_type.RESIDENCE_PERMIT, document_type.STATELESS_CERTIFICATE ]) if request.POST.get( "criteria_5" ) == assimilation_criteria_enum.CRITERIA_3: list_document_type_needed.extend([ document_type.FAMILY_COMPOSITION, document_type.PAYCHECK_1, document_type.PAYCHECK_2, document_type.PAYCHECK_3, document_type.PAYCHECK_4, document_type.PAYCHECK_5, document_type.PAYCHECK_6, document_type.RESIDENT_CERTIFICATE, document_type.ID_CARD ]) if request.POST.get( "criteria_5" ) == assimilation_criteria_enum.CRITERIA_4: list_document_type_needed.extend( [document_type.CPAS]) for basic_doc_description in assimilation_basic_documents: if basic_doc_description not in list_document_type_needed: app_doc_files = mdl.applicant_document_file.\ find_by_applicant_and_description(applicant, basic_doc_description) for app_doc_file in app_doc_files: # delete unnecessary documents app_doc_file.document_file.delete() applicant_assimilation_criteria.additional_criteria = \ define_additional_criteria(request.POST.get("criteria_5")) applicant_assimilation_criteria.selected = True applicant_assimilation_criteria.save() # Update/create application_assimilation_criteria if application: application_assimilation_criteria = mdl.application_assimilation_criteria.\ find_first(application, criteria) application_assimilation_criteria.criteria = criteria if applicant_assimilation_criteria.additional_criteria: application_assimilation_criteria.additional_criteria = \ applicant_assimilation_criteria.additional_criteria application_assimilation_criteria.selected = True application_assimilation_criteria.save() if request.POST[key] == "false": applicant_assimilation_criteria.selected = False applicant_assimilation_criteria.save() # Update/create application_assimilation_criteria if application: application_assimilation_criteria = mdl.application_assimilation_criteria.\ find_first(application, criteria) application_assimilation_criteria.criteria = criteria if applicant_assimilation_criteria.additional_criteria: application_assimilation_criteria.additional_criteria = \ applicant_assimilation_criteria.additional_criteria application_assimilation_criteria.selected = False application_assimilation_criteria.save() else: # cleanup the database if needed delete_previous_criteria(applicant, application) message_success = None if person_contact_address: person_contact_address.save() person_legal_address.save() applicant.user.save() if application: application.application_type = mdl.application.define_application_type( application.coverage_access_degree, request.user) application.save() request.user = applicant.user # Otherwise it was not refreshed while going back to home page applicant.save() message_info = _('msg_info_saved') following_tab = navigation.get_following_tab(request, 'profile', application) if following_tab: return following_tab else: applicant = mdl.applicant.find_by_user(request.user) applicant_form = ApplicantForm() if applicant: person_contact_address = mdl.person_address.find_by_person_type( applicant, 'CONTACT') same_addresses = True if person_contact_address: same_addresses = False previous_enrollment = False if applicant.registration_id or applicant.last_academic_year: previous_enrollment = True else: return HttpResponseRedirect('/admission/logout') countries = mdl_ref.country.find_all() props = mdl.properties.find_by_key('INSTITUTION') if props: institution_name = props.value else: institution_name = None assimilation_criteria = assimilation_criteria_enum.ASSIMILATION_CRITERIA_CHOICES applicant_assimilation_criteria = mdl.applicant_assimilation_criteria.find_by_applicant( applicant.id) # validated are not ready yet, to be achieved in another issue - Leila person_legal_address = mdl.person_address.find_by_person_type( applicant, 'LEGAL') person_contact_address = mdl.person_address.find_by_person_type( applicant, 'CONTACT') document_formset = UploadDocumentFileForm() data = { 'applicant': applicant, 'applicant_form': applicant_form, 'countries': countries, 'assimilation_criteria': assimilation_criteria, 'applicant_assimilation_criteria': applicant_assimilation_criteria, 'person_legal_address': person_legal_address, 'person_contact_address': person_contact_address, 'same_addresses': same_addresses, 'previous_enrollment': previous_enrollment, 'institution': institution_name, 'message_success': message_success, 'tab_active': navigation.PROFILE_TAB, 'application': application, 'applications': mdl.application.find_by_user(request.user), 'picture': get_picture_id(request.user), 'id_document': get_id_document(request.user), 'assimilation_basic_documents': assimilation_criteria_view.find_assimilation_basic_documents(), 'assimilation_documents_existing': get_assimilation_documents_existing(request.user), 'document_formset': document_formset, 'message_info': message_info } data.update( demande_validation.get_validation_status(application, applicant)) return render(request, "admission_home.html", data)
def diploma_save(request): next_step = False previous_step = False save_step = True if request.POST: if 'bt_next_step_up' in request.POST or 'bt_next_step_down' in request.POST: next_step = True else: if 'bt_previous_step_up' in request.POST or 'bt_previous_step_down' in request.POST: previous_step = True if 'submit_diploma' in request.POST: save_step = True application = mdl.application.find_first_by_user(request.user) applicant = mdl.applicant.find_by_user(request.user) secondary_education = mdl.secondary_education.find_by_person(applicant) if secondary_education is None: secondary_education = mdl.secondary_education.SecondaryEducation() secondary_education.academic_year = mdl_base.academic_year.current_academic_year() secondary_education.person = applicant if next_step or previous_step or save_step: secondary_education = populate_secondary_education(request, secondary_education) secondary_education.save() professional_exam = get_professional_exam(request, secondary_education) secondary_education_exam_update(secondary_education, PROFESSIONAL_TYPE, professional_exam) admission_exam = get_admission_exam(request, secondary_education) secondary_education_exam_update(secondary_education, ADMISSION_EXAM_TYPE, admission_exam) local_language_exam = get_local_language_exam(request, secondary_education) secondary_education_exam_update(secondary_education, LANGUAGE_EXAM_TYPE, local_language_exam) message_success = _('msg_info_saved') # Check if documents need to be deleted documents_update(request, secondary_education, application, professional_exam, admission_exam) if next_step: return render(request, "curriculum.html", {"application": application, "message_success": message_success}) else: if previous_step: return HttpResponseRedirect(reverse('home')) app_id = None if application: app_id = application.id following_tab = navigation.get_following_tab(request, 'diploma', application) if following_tab: return following_tab data = get_prerequis_data(request, 1, app_id) data.update({"secondary_education": secondary_education}) validation_messages = demande_validation.validate_diploma(application, secondary_education) if len(validation_messages) > 0: data.update({"validation_messages": validation_messages}) data.update({"validated_diploma": False}) else: data.update({"validation_messages": None}) data.update({"validated_diploma": True}) return render(request, "admission_home.html", data)
def save(request, application_id=None): save_step = False duplicate = False duplicate_year_origin = None validation_messages = {} if application_id: application = mdl.application.find_by_id(application_id) else: application = mdl.application.init_application(request.user) key = 'bt_duplicate_' for k, v in request.POST.items(): if k.startswith(key): duplicate = True duplicate_year_origin = int(k.replace(key, '')) break if duplicate: pass else: save_step = True message_success = None # Get the data in bd for dropdown list local_universities_french = mdl_reference.education_institution \ .find_by_institution_type_national_community(education_institution_type.UNIVERSITY, national_cmunity_type.FRENCH, False) local_universities_dutch = mdl_reference.education_institution \ .find_by_institution_type_national_community(education_institution_type.UNIVERSITY, national_cmunity_type.DUTCH, False) universities_cities = [] universities = [] if save_step or duplicate: is_valid, validation_messages, curricula, universities_cities, universities, duplication_possible \ = validate_fields_form(request, duplicate_year_origin) is_valid = True # a modifier avec issue 180 if is_valid: message_success = _('msg_info_saved') for curriculum in curricula: curriculum.save() following_tab = navigation.get_following_tab( request, 'curriculum', application) if following_tab: return following_tab else: return render( request, "admission_home.html", { "curricula": curricula, "local_universities_french": local_universities_french, "local_universities_dutch": local_universities_dutch, "domains": mdl_reference.domain.find_current_domains(), "subdomains": mdl_reference.domain.find_parent_domains(), "grade_types": mdl_reference.grade_type.find_all(), "validation_messages": validation_messages, "message_success": message_success, "universities_cities": universities_cities, "universities": universities, "languages": mdl_reference.language.find_languages(), "current_academic_year": mdl_base.academic_year.current_academic_year(), "tab_active": navigation.CURRICULUM_TAB, "application": application }) # Get the data in bd applicant = mdl.applicant.find_by_user(request.user) first_academic_year_for_cv = None curricula = [] # find existing cv secondary_education = mdl.secondary_education.find_by_person(applicant) if secondary_education: if secondary_education.academic_year: first_academic_year_for_cv = secondary_education.academic_year + 1 current_academic_year = mdl_base.academic_year.current_academic_year().year year = first_academic_year_for_cv if year: while year < current_academic_year: curriculum = mdl.curriculum.find_by_person_year(applicant, year) if curriculum is None: # add cv empty cv's for the year if it's needed curriculum = mdl.curriculum.Curriculum() curriculum.person = applicant curriculum.academic_year = year curricula.append(curriculum) year += 1 return render( request, "admission_home.html", { "curricula": curricula, "local_universities_french": local_universities_french, "local_universities_dutch": local_universities_dutch, "domains": mdl_reference.domain.find_current_domains(), "subdomains": mdl_reference.domain.find_parent_domains(), "grade_types": mdl_reference.grade_type.find_all(), "universities_countries": mdl_reference.education_institution.find_countries(), "validation_messages": validation_messages, "message_success": message_success, "universities_cities": universities_cities, "universities": universities, "languages": mdl_reference.language.find_languages(), "current_academic_year": mdl_base.academic_year.current_academic_year(), "tab_active": navigation.CURRICULUM_TAB, "application": application })
def profile(request, application_id=None, message_success=None): message_info = None application = None assimilation_case = False if application_id: application = mdl.application.find_by_id(application_id) if request.method == 'POST': applicant_form = ApplicantForm(data=request.POST) applicant = mdl.applicant.find_by_user(request.user) person_legal_address = mdl.person_address.find_by_person_type(applicant, 'LEGAL') if person_legal_address is None: person_legal_address = mdl.person_address.PersonAddress() person_legal_address.person = applicant person_legal_address.type = 'LEGAL' if request.POST['last_name']: applicant.user.last_name = request.POST['last_name'] else: applicant.user.last_name = None if request.POST['first_name']: applicant.user.first_name = request.POST['first_name'] else: applicant.user.first_name = None if request.POST['middle_name']: applicant.middle_name = request.POST['middle_name'] else: applicant.middle_name = None if request.POST['birth_date']: try: applicant.birth_date = datetime.strptime(request.POST['birth_date'], '%d/%m/%Y') except ValueError: applicant.birth_date = None applicant_form.errors['birth_date'] = "La date encodée('%s') semble incorrecte " % request.POST[ 'birth_date'] else: applicant.birth_date = None if request.POST['birth_place']: applicant.birth_place = request.POST['birth_place'] else: applicant.birth_place = None if request.POST.get('birth_country'): birth_country_id = request.POST['birth_country'] if birth_country_id and int(birth_country_id) >= 0: birth_country = mdl_ref.country.find_by_id(birth_country_id) else: birth_country = None applicant.birth_country = birth_country else: applicant.birth_country = None if request.POST.get('gender'): applicant.gender = request.POST['gender'] else: applicant.gender = None if request.POST['civil_status']: applicant.civil_status = request.POST['civil_status'] else: applicant.civil_status = None if request.POST['number_children']: applicant.number_children = request.POST['number_children'] else: applicant.number_children = None if request.POST['spouse_name']: applicant.spouse_name = request.POST['spouse_name'] else: applicant.spouse_name = None if request.POST.get('nationality') and not request.POST.get('nationality') == "-1": country_id = request.POST['nationality'] if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) else: country = None if country: if not country.european_union: assimilation_case = True applicant.nationality = country else: applicant.nationality = None if request.POST['national_id']: applicant.national_id = request.POST['national_id'] else: applicant.national_id = None if request.POST['id_card_number']: applicant.id_card_number = request.POST['id_card_number'] else: applicant.id_card_number = None if request.POST['passport_number']: applicant.passport_number = request.POST['passport_number'] else: applicant.passport_number = None if request.POST['legal_adr_street']: person_legal_address.street = request.POST['legal_adr_street'] else: person_legal_address.street = '' if request.POST['legal_adr_number']: person_legal_address.number = request.POST['legal_adr_number'] else: person_legal_address.number = '' if request.POST['legal_adr_complement']: person_legal_address.complement = request.POST['legal_adr_complement'] else: person_legal_address.complement = None if request.POST['legal_adr_postal_code']: person_legal_address.postal_code = request.POST['legal_adr_postal_code'] else: person_legal_address.postal_code = '' if request.POST['legal_adr_city']: person_legal_address.city = request.POST['legal_adr_city'] else: person_legal_address.city = '' if request.POST.get('legal_adr_country') and not request.POST.get('legal_adr_country') == "-1": country_id = request.POST['legal_adr_country'] country = None if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) person_legal_address.country = country else: applicant_form.errors['legal_adr_country'] = _('mandatory_field') if request.POST.get('same_contact_legal_addr') == "false": person_contact_address = mdl.person_address.find_by_person_type(applicant, 'CONTACT') if person_contact_address is None: person_contact_address = mdl.person_address.PersonAddress() person_contact_address.person = applicant person_contact_address.type = 'CONTACT' if request.POST['contact_adr_street']: person_contact_address.street = request.POST['contact_adr_street'] else: person_contact_address.street = None if request.POST['contact_adr_number']: person_contact_address.number = request.POST['contact_adr_number'] else: person_contact_address.number = None if request.POST['contact_adr_complement']: person_contact_address.complement = request.POST['contact_adr_complement'] else: person_contact_address.complement = None if request.POST['contact_adr_postal_code']: person_contact_address.postal_code = request.POST['contact_adr_postal_code'] else: person_contact_address.postal_code = None if request.POST['contact_adr_city']: person_contact_address.city = request.POST['contact_adr_city'] else: person_contact_address.city = None if request.POST['contact_adr_country']: country_id = request.POST['contact_adr_country'] country = None if country_id and int(country_id) >= 0: country = mdl_ref.country.find_by_id(country_id) if country: person_contact_address.country = country else: person_contact_address.country = None same_addresses = False person_contact_address.save() else: same_addresses = True person_contact_address = mdl.person_address.find_by_person_type(applicant, 'CONTACT') if person_contact_address: person_contact_address.delete() person_contact_address = None if request.POST['phone_mobile']: applicant.phone_mobile = request.POST['phone_mobile'] if request.POST['phone']: applicant.phone = request.POST['phone'] else: applicant.phone = None if request.POST['previous_enrollment'] == "true": if request.POST['registration_id']: applicant.registration_id = request.POST['registration_id'] else: applicant.registration_id = None if request.POST['last_academic_year']: applicant.last_academic_year = request.POST['last_academic_year'] else: applicant.last_academic_year = None previous_enrollment = True else: applicant.registration_id = None applicant.last_academic_year = None previous_enrollment = False if assimilation_case: # verify if it exists one record per criteria default_criteria_list = assimilation_criteria_enum.ASSIMILATION_CRITERIA_CHOICES for criteria in default_criteria_list: crit = criteria[0] existing_crit = mdl.applicant_assimilation_criteria.find_first(applicant, crit) if existing_crit is None: applicant_assimilation_criteria = \ mdl.applicant_assimilation_criteria.ApplicantAssimilationCriteria() applicant_assimilation_criteria.criteria = crit applicant_assimilation_criteria.applicant = applicant applicant_assimilation_criteria.additional_criteria = None applicant_assimilation_criteria.selected = None applicant_assimilation_criteria.save() if application: application_assimilation_criteria = mdl.application_assimilation_criteria.find_first(application, crit) if application_assimilation_criteria is None: application_assimilation_criteria = \ mdl.application_assimilation_criteria.ApplicationAssimilationCriteria() application_assimilation_criteria.criteria = crit application_assimilation_criteria.application = application application_assimilation_criteria.additional_criteria = None application_assimilation_criteria.selected = None application_assimilation_criteria.save() for key in request.POST: if key[0:len(RADIO_NAME_ASSIMILATION_CRITERIA)] == RADIO_NAME_ASSIMILATION_CRITERIA: criteria_id = key[len(RADIO_NAME_ASSIMILATION_CRITERIA):] criteria_ref = assimilation_criteria_enum.find(criteria_id) criteria = criteria_ref[0] applicant_assimilation_criteria = mdl.applicant_assimilation_criteria.find_first(applicant, criteria) if applicant_assimilation_criteria is None: applicant_assimilation_criteria = mdl.applicant_assimilation_criteria\ .ApplicantAssimilationCriteria() applicant_assimilation_criteria.criteria = criteria applicant_assimilation_criteria.applicant = applicant if request.POST[key] == "true": if criteria: assimilation_basic_documents = assimilation_criteria_view.\ find_list_assimilation_basic_documents() list_document_type_needed = assimilation_criteria_view.\ get_list_documents_descriptions(criteria) list_document_type_needed.append(document_type.ID_CARD) if criteria == assimilation_criteria_enum.CRITERIA_5: if request.POST.get("criteria_5") == assimilation_criteria_enum.CRITERIA_1: list_document_type_needed.extend([document_type.RESIDENT_LONG_DURATION, document_type.ID_FOREIGN_UNLIMITED]) if request.POST.get("criteria_5") == assimilation_criteria_enum.CRITERIA_2: list_document_type_needed.extend([ document_type.ATTACHMENT_26, document_type.REFUGEE_CARD, document_type.FAMILY_COMPOSITION, document_type.BIRTH_CERTIFICATE, document_type.REFUGEE_CARD, document_type.RESIDENT_CERTIFICATE, document_type.FOREIGN_INSCRIPTION_CERTIFICATE, document_type.SUBSIDIARY_PROTECTION_DECISION, document_type.RESIDENCE_PERMIT, document_type.STATELESS_CERTIFICATE]) if request.POST.get("criteria_5") == assimilation_criteria_enum.CRITERIA_3: list_document_type_needed.extend([document_type.FAMILY_COMPOSITION, document_type.PAYCHECK_1, document_type.PAYCHECK_2, document_type.PAYCHECK_3, document_type.PAYCHECK_4, document_type.PAYCHECK_5, document_type.PAYCHECK_6, document_type.RESIDENT_CERTIFICATE, document_type.ID_CARD]) if request.POST.get("criteria_5") == assimilation_criteria_enum.CRITERIA_4: list_document_type_needed.extend([document_type.CPAS]) for basic_doc_description in assimilation_basic_documents: if basic_doc_description not in list_document_type_needed: app_doc_files = mdl.applicant_document_file.\ find_by_applicant_and_description(applicant, basic_doc_description) for app_doc_file in app_doc_files: # delete unnecessary documents app_doc_file.document_file.delete() applicant_assimilation_criteria.additional_criteria = \ define_additional_criteria(request.POST.get("criteria_5")) applicant_assimilation_criteria.selected = True applicant_assimilation_criteria.save() # Update/create application_assimilation_criteria if application: application_assimilation_criteria = mdl.application_assimilation_criteria.\ find_first(application, criteria) application_assimilation_criteria.criteria = criteria if applicant_assimilation_criteria.additional_criteria: application_assimilation_criteria.additional_criteria = \ applicant_assimilation_criteria.additional_criteria application_assimilation_criteria.selected = True application_assimilation_criteria.save() if request.POST[key] == "false": applicant_assimilation_criteria.selected = False applicant_assimilation_criteria.save() # Update/create application_assimilation_criteria if application: application_assimilation_criteria = mdl.application_assimilation_criteria.\ find_first(application, criteria) application_assimilation_criteria.criteria = criteria if applicant_assimilation_criteria.additional_criteria: application_assimilation_criteria.additional_criteria = \ applicant_assimilation_criteria.additional_criteria application_assimilation_criteria.selected = False application_assimilation_criteria.save() else: # cleanup the database if needed delete_previous_criteria(applicant, application) message_success = None if person_contact_address: person_contact_address.save() person_legal_address.save() applicant.user.save() if application: application.application_type = mdl.application.define_application_type(application.coverage_access_degree, request.user) application.save() request.user = applicant.user # Otherwise it was not refreshed while going back to home page applicant.save() message_info = _('msg_info_saved') following_tab = navigation.get_following_tab(request, 'profile', application) if following_tab: return following_tab else: applicant = mdl.applicant.find_by_user(request.user) applicant_form = ApplicantForm() if applicant: person_contact_address = mdl.person_address.find_by_person_type(applicant, 'CONTACT') same_addresses = True if person_contact_address: same_addresses = False previous_enrollment = False if applicant.registration_id or applicant.last_academic_year: previous_enrollment = True else: return HttpResponseRedirect('/admission/logout') countries = mdl_ref.country.find_all() props = mdl.properties.find_by_key('INSTITUTION') if props: institution_name = props.value else: institution_name = None assimilation_criteria = assimilation_criteria_enum.ASSIMILATION_CRITERIA_CHOICES applicant_assimilation_criteria = mdl.applicant_assimilation_criteria.find_by_applicant(applicant.id) # validated are not ready yet, to be achieved in another issue - Leila person_legal_address = mdl.person_address.find_by_person_type(applicant, 'LEGAL') person_contact_address = mdl.person_address.find_by_person_type(applicant, 'CONTACT') document_formset = UploadDocumentFileForm() data = { 'applicant': applicant, 'applicant_form': applicant_form, 'countries': countries, 'assimilation_criteria': assimilation_criteria, 'applicant_assimilation_criteria': applicant_assimilation_criteria, 'person_legal_address': person_legal_address, 'person_contact_address': person_contact_address, 'same_addresses': same_addresses, 'previous_enrollment': previous_enrollment, 'institution': institution_name, 'message_success': message_success, 'tab_active': navigation.PROFILE_TAB, 'application': application, 'applications': mdl.application.find_by_user(request.user), 'picture': get_picture_id(request.user), 'id_document': get_id_document(request.user), 'assimilation_basic_documents': assimilation_criteria_view.find_assimilation_basic_documents(), 'assimilation_documents_existing': get_assimilation_documents_existing(request.user), 'document_formset': document_formset, 'message_info': message_info} data.update(demande_validation.get_validation_status(application, applicant)) return render(request, "admission_home.html", data)