Exemple #1
0
def save_uploaded_file(request):
    if request.method == 'POST':
        if request.POST.get('application_id'):
            application = mdl.application.find_by_id(
                request.POST.get('application_id'))
            applicant = application.applicant
        else:
            application = None
            applicant = mdl.applicant.find_by_user(request.user)

        description = request.POST.get('description')

        prerequis_uploads = get_prerequis_document_types()
        assimilation_uploads = assimilation_criteria_view.find_list_assimilation_basic_documents(
        )

        if description in prerequis_uploads or description in assimilation_uploads:
            delete_existing_application_documents(application, description)

        if description == document_type.ID_PICTURE \
                or description == document_type.ID_CARD:
            delete_existing_applicant_documents(applicant, description)

        doc_file = create_document_file(description, request)
        applicant_document_file = mdl.applicant_document_file.ApplicantDocumentFile(
            applicant=applicant, document_file=doc_file)
        applicant_document_file.save()

        if description in prerequis_uploads:
            adm_doc_file = mdl.application_document_file.ApplicationDocumentFile(
            )
            adm_doc_file.application = application
            adm_doc_file.document_file = doc_file
            adm_doc_file.save()
            if description == document_type.PROFESSIONAL_EXAM_CERTIFICATE:
                secondary_education = mdl.secondary_education.find_by_person(
                    applicant)
                secondary_education_exam_type = 'PROFESSIONAL'
                if secondary_education is None:
                    secondary_education = mdl.secondary_education.SecondaryEducation(
                    )
                    secondary_education.person = applicant
                    secondary_education.save()

                secondary_education_exams = mdl.secondary_education_exam.search(
                    None, secondary_education, secondary_education_exam_type)
                if not secondary_education_exams.exists():
                    secondary_education_exam = mdl.secondary_education_exam.SecondaryEducationExam(
                    )
                    secondary_education_exam.secondary_education = secondary_education
                    secondary_education_exam.type = secondary_education_exam_type
                    secondary_education_exam.save()

    return HttpResponse('')
Exemple #2
0
def get_assimilation_documents_existing(user):
    applicant = mdl.applicant.find_by_user(user)
    assimilation_basic_documents = assimilation_criteria_view.find_list_assimilation_basic_documents()
    docs = []
    for document_type_description in assimilation_basic_documents:
        app_doc_files = mdl.applicant_document_file\
                       .find_by_applicant_and_description(applicant, document_type_description)
        if app_doc_files:
            document_files = []
            for app_doc_file in app_doc_files:
                document_files.append(app_doc_file.document_file)
            docs.extend(document_files)

    return docs
Exemple #3
0
def save_uploaded_file(request):
    if request.method == 'POST':
        if request.POST.get('application_id'):
            application = mdl.application.find_by_id(request.POST.get('application_id'))
            applicant = application.applicant
        else:
            application = None
            applicant = mdl.applicant.find_by_user(request.user)

        description = request.POST.get('description')

        prerequis_uploads = get_prerequis_document_types()
        assimilation_uploads = assimilation_criteria_view.find_list_assimilation_basic_documents()

        if description in prerequis_uploads or description in assimilation_uploads:
            delete_existing_application_documents(application, description)

        if description == document_type.ID_PICTURE \
                or description == document_type.ID_CARD:
            delete_existing_applicant_documents(applicant, description)

        doc_file = create_document_file(description, request)
        applicant_document_file = mdl.applicant_document_file.ApplicantDocumentFile(applicant=applicant,
                                                                                    document_file=doc_file)
        applicant_document_file.save()

        if description in prerequis_uploads:
            adm_doc_file = mdl.application_document_file.ApplicationDocumentFile()
            adm_doc_file.application = application
            adm_doc_file.document_file = doc_file
            adm_doc_file.save()
            if description == document_type.PROFESSIONAL_EXAM_CERTIFICATE:
                secondary_education = mdl.secondary_education.find_by_person(applicant)
                secondary_education_exam_type = 'PROFESSIONAL'
                if secondary_education is None:
                    secondary_education = mdl.secondary_education.SecondaryEducation()
                    secondary_education.person = applicant
                    secondary_education.save()

                secondary_education_exams = mdl.secondary_education_exam.search(None,
                                                                                secondary_education,
                                                                                secondary_education_exam_type)
                if not secondary_education_exams.exists():
                    secondary_education_exam = mdl.secondary_education_exam.SecondaryEducationExam()
                    secondary_education_exam.secondary_education = secondary_education
                    secondary_education_exam.type = secondary_education_exam_type
                    secondary_education_exam.save()

    return HttpResponse('')
Exemple #4
0
def get_assimilation_documents_existing(user):
    applicant = mdl.applicant.find_by_user(user)
    assimilation_basic_documents = assimilation_criteria_view.find_list_assimilation_basic_documents(
    )
    docs = []
    for document_type_description in assimilation_basic_documents:
        app_doc_files = mdl.applicant_document_file\
                       .find_by_applicant_and_description(applicant, document_type_description)
        if app_doc_files:
            document_files = []
            for app_doc_file in app_doc_files:
                document_files.append(app_doc_file.document_file)
            docs.extend(document_files)

    return docs
Exemple #5
0
def documents_upload(request):
    assimilation_uploads = assimilation_criteria_view.find_list_assimilation_basic_documents(
    )
    applicant = mdl.applicant.find_by_user(request.user)
    prerequisites_uploads = [
        document_type.NATIONAL_DIPLOMA_RECTO,
        document_type.NATIONAL_DIPLOMA_VERSO,
        document_type.INTERNATIONAL_DIPLOMA_RECTO,
        document_type.INTERNATIONAL_DIPLOMA_VERSO,
        document_type.TRANSLATED_INTERNATIONAL_DIPLOMA_RECTO,
        document_type.TRANSLATED_INTERNATIONAL_DIPLOMA_VERSO,
        document_type.HIGH_SCHOOL_SCORES_TRANSCRIPT_RECTO,
        document_type.HIGH_SCHOOL_SCORES_TRANSCRIPT_VERSO,
        document_type.TRANSLATED_HIGH_SCHOOL_SCORES_TRANSCRIPT_RECTO,
        document_type.TRANSLATED_HIGH_SCHOOL_SCORES_TRANSCRIPT_VERSO,
        document_type.EQUIVALENCE, document_type.ADMISSION_EXAM_CERTIFICATE,
        document_type.PROFESSIONAL_EXAM_CERTIFICATE
    ]
    application = None

    if request.POST.get('application_id'):
        application_id = request.POST['application_id']
        application = mdl.application.find_by_id(application_id)
    for key in request.POST:
        if key[0:26] == "uploaded_file_description_":
            if request.POST[key]:
                file_description = key[26:]
                if request.POST["uploaded_file_name_" + file_description]:
                    fn = request.POST["uploaded_file_name_" + file_description]
                    file = request.FILES["uploaded_file_" + file_description]
                    if file_description in prerequisites_uploads:
                        app_doc_files = mdl.applicant_document_file\
                            .find_by_applicant_and_description(applicant, file_description)
                        for app_doc_file in app_doc_files:
                            app_doc_file.document_file.delete()

                    if file_description == document_type.ID_PICTURE \
                        or file_description == document_type.ID_CARD \
                        or file_description in prerequisites_uploads \
                            or file_description in assimilation_uploads:
                        # Delete older file with the same description
                        app_doc_files = mdl.applicant_document_file\
                            .find_by_applicant_and_description(applicant, file_description)
                        for app_doc_file in app_doc_files:
                            app_doc_file.document_file.delete()

                        storage_duration = 0
                        content_type = file.content_type
                        size = file.size

                        doc_file = mdl_osis_common.document_file.DocumentFile(
                            file_name=fn,
                            file=file,
                            description=file_description,
                            storage_duration=storage_duration,
                            application_name='admission',
                            content_type=content_type,
                            size=size,
                            update_by=request.user.username)
                        doc_file.save()
                        applicant_document_file = mdl.applicant_document_file\
                                                     .ApplicantDocumentFile(applicant=applicant, document_file=doc_file)
                        applicant_document_file.save()
                        if file_description in prerequisites_uploads:
                            adm_doc_file = mdl.application_document_file.ApplicationDocumentFile(
                            )
                            adm_doc_file.application = application
                            adm_doc_file.document_file = doc_file
                            adm_doc_file.save()
Exemple #6
0
def documents_upload(request):
    assimilation_uploads = assimilation_criteria_view.find_list_assimilation_basic_documents()
    applicant = mdl.applicant.find_by_user(request.user)
    prerequisites_uploads = [document_type.NATIONAL_DIPLOMA_RECTO,
                             document_type.NATIONAL_DIPLOMA_VERSO,
                             document_type.INTERNATIONAL_DIPLOMA_RECTO,
                             document_type.INTERNATIONAL_DIPLOMA_VERSO,
                             document_type.TRANSLATED_INTERNATIONAL_DIPLOMA_RECTO,
                             document_type.TRANSLATED_INTERNATIONAL_DIPLOMA_VERSO,
                             document_type.HIGH_SCHOOL_SCORES_TRANSCRIPT_RECTO,
                             document_type.HIGH_SCHOOL_SCORES_TRANSCRIPT_VERSO,
                             document_type.TRANSLATED_HIGH_SCHOOL_SCORES_TRANSCRIPT_RECTO,
                             document_type.TRANSLATED_HIGH_SCHOOL_SCORES_TRANSCRIPT_VERSO,
                             document_type.EQUIVALENCE,
                             document_type.ADMISSION_EXAM_CERTIFICATE,
                             document_type.PROFESSIONAL_EXAM_CERTIFICATE]
    application = None

    if request.POST.get('application_id'):
        application_id = request.POST['application_id']
        application = mdl.application.find_by_id(application_id)
    for key in request.POST:
        if key[0:26] == "uploaded_file_description_":
            if request.POST[key]:
                file_description = key[26:]
                if request.POST["uploaded_file_name_"+file_description]:
                    fn = request.POST["uploaded_file_name_"+file_description]
                    file = request.FILES["uploaded_file_"+file_description]
                    if file_description in prerequisites_uploads:
                        app_doc_files = mdl.applicant_document_file\
                            .find_by_applicant_and_description(applicant, file_description)
                        for app_doc_file in app_doc_files:
                            app_doc_file.document_file.delete()

                    if file_description == document_type.ID_PICTURE \
                        or file_description == document_type.ID_CARD \
                        or file_description in prerequisites_uploads \
                            or file_description in assimilation_uploads:
                        # Delete older file with the same description
                        app_doc_files = mdl.applicant_document_file\
                            .find_by_applicant_and_description(applicant, file_description)
                        for app_doc_file in app_doc_files:
                            app_doc_file.document_file.delete()

                        storage_duration = 0
                        content_type = file.content_type
                        size = file.size

                        doc_file = mdl_osis_common.document_file.DocumentFile(file_name=fn,
                                                                              file=file,
                                                                              description=file_description,
                                                                              storage_duration=storage_duration,
                                                                              application_name='admission',
                                                                              content_type=content_type,
                                                                              size=size,
                                                                              update_by=request.user.username)
                        doc_file.save()
                        applicant_document_file = mdl.applicant_document_file\
                                                     .ApplicantDocumentFile(applicant=applicant, document_file=doc_file)
                        applicant_document_file.save()
                        if file_description in prerequisites_uploads:
                            adm_doc_file = mdl.application_document_file.ApplicationDocumentFile()
                            adm_doc_file.application = application
                            adm_doc_file.document_file = doc_file
                            adm_doc_file.save()