Exemple #1
0
def registration_edit(request, admission_id):
    admission = get_object_or_404(
        Admission.objects.select_related(
            'billing_address',
            'residence_address',
            'address'
        ),
        pk=admission_id
    )
    can_access_admission(request.user, admission)

    if admission.is_draft():
        raise PermissionDenied

    address = admission.address
    billing_address = admission.billing_address
    residence_address = admission.residence_address
    registration_form = RegistrationForm(request.POST or None, instance=admission, user=request.user)
    billing_address_form = AddressForm(request.POST or None, instance=admission.billing_address, prefix="billing")
    residence_address_form = AddressForm(request.POST or None, instance=admission.residence_address, prefix="residence")

    errors = []
    if registration_form.is_valid() and billing_address_form.is_valid() and residence_address_form.is_valid():
        billing_address = _update_or_create_specific_address(
            admission.address,
            billing_address,
            billing_address_form,
            not registration_form.cleaned_data['use_address_for_billing']
        )
        residence_address = _update_or_create_specific_address(
            admission.address,
            residence_address,
            residence_address_form,
            not registration_form.cleaned_data['use_address_for_post']
        )
        admission = registration_form.save(commit=False)
        admission.address = address
        admission.billing_address = billing_address
        admission.residence_address = residence_address
        message = get_appropriate_revision_message(registration_form)
        save_and_create_revision(message, admission, request.user)

        return redirect(reverse('admission_detail', kwargs={'admission_id': admission_id}) + "#registration")
    else:
        errors.append(registration_form.errors)

    return render(
        request,
        'registration_form.html',
        {
            'admission': admission,
            'registration_form': registration_form,
            'billing_address_form': billing_address_form,
            'residence_address_form': residence_address_form,
            'errors': errors,
        }
    )
Exemple #2
0
def archive_procedure(request, admission_id):
    admission = get_object_or_404(Admission,
                                  pk=admission_id) if admission_id else None
    can_access_admission(request.user, admission)
    if admission.is_draft():
        raise PermissionDenied
    redirection = request.META.get('HTTP_REFERER')
    admission = _switch_archived_state(request.user, admission_id)
    _set_success_message(request, False, admission.archived)
    return HttpResponseRedirect(redirection)
Exemple #3
0
def change_archive_status(new_archive_status, request):
    selected_admissions_id = request.POST.getlist("selected_action",
                                                  default=[])
    for admission_id in selected_admissions_id:
        admission = Admission.objects.get(id=admission_id)
        can_access_admission(request.user, admission)
    redirection = request.META.get('HTTP_REFERER')
    if selected_admissions_id:
        _mark_folders_as_archived(request, selected_admissions_id,
                                  new_archive_status)
        return redirect(reverse('archive'))
    else:
        _set_error_message(request)
        return HttpResponseRedirect(redirection)
Exemple #4
0
def billing_edit(request, admission_id):
    admission = get_object_or_404(Admission, pk=admission_id)
    can_access_admission(request.user, admission)

    if admission.is_draft() or admission.formation.registration_required:
        raise PermissionDenied

    registration_form = RegistrationForm(request.POST or None,
                                         instance=admission,
                                         only_billing=True,
                                         user=request.user)
    address = admission.address
    billing_address = admission.billing_address
    billing_address_form = AddressForm(request.POST or None,
                                       instance=admission.billing_address,
                                       prefix="billing")

    errors = []
    if registration_form.is_valid() and billing_address_form.is_valid():
        billing_address = _update_or_create_specific_address(
            address, billing_address, billing_address_form,
            not registration_form.cleaned_data['use_address_for_billing'])

        admission = registration_form.save(commit=False)
        admission.billing_address = billing_address
        admission.save()

        return redirect(
            reverse('admission_detail', kwargs={'admission_id': admission_id})
            + "#billing")
    else:
        errors.append(
            billing_address_form.errors.update(registration_form.errors))

    return render(
        request, 'admission_billing_form.html', {
            'admission': admission,
            'registration_form': registration_form,
            'billing_address_form': billing_address_form,
            'errors': errors,
        })
def admission_detail(request, admission_id):
    user_is_continuing_education_student_worker = is_continuing_education_student_worker(request.user)

    admission = get_object_or_404(
        Admission.objects.select_related(
            'billing_address__country',
            'address__country',
            'person_information__person',
            'person_information__birth_country',
            'citizenship',
            'formation__education_group',
        ).prefetch_related('formation__managers'),
        pk=admission_id
    )
    if not user_is_continuing_education_student_worker:
        can_access_admission(request.user, admission)

    files = AdmissionFile.objects.filter(admission=admission_id)
    accepted_states = admission_state_choices.NEW_ADMIN_STATE[admission.state]
    states = _get_states_choices(accepted_states, admission, request)

    adm_form = AdmissionForm(
        request.POST or None,
        instance=admission,
    )

    version_list = get_versions(admission)

    if request.method == 'POST' and request.FILES:
        return _upload_file(request, admission)

    rejected_adm_form = RejectedAdmissionForm(
        request.POST or None,
        instance=admission,
        prefix='rejected',
    )

    waiting_adm_form = WaitingAdmissionForm(
        request.POST or None,
        instance=admission,
    )

    condition_acceptance_adm_form = ConditionAcceptanceAdmissionForm(
        request.POST or None,
        instance=admission,
    )

    cancel_adm_form = CancelAdmissionForm(
        request.POST or None,
        instance=admission,
    )

    admission._original_state = admission.state
    if adm_form.is_valid():
        forms = (adm_form, waiting_adm_form, rejected_adm_form, condition_acceptance_adm_form, cancel_adm_form)
        return _change_state(request, forms, accepted_states, admission)

    _display_adapted_ucl_registration_message(admission, request)

    return render(
        request, "admission_detail.html",
        {
            'admission': admission,
            'files': files,
            'states': states,
            'admission_form': adm_form,
            'rejected_adm_form': rejected_adm_form,
            'waiting_adm_form': waiting_adm_form,
            'cancel_adm_form': cancel_adm_form,
            'file_categories_choices': _get_file_category_choices_with_disabled_parameter(admission),
            'invoice': file_category_choices.INVOICE,
            'condition_acceptance_adm_form': condition_acceptance_adm_form,
            'user_is_continuing_education_student_worker': user_is_continuing_education_student_worker,
            'version': version_list,
            'MAX_UPLOAD_SIZE': MAX_UPLOAD_SIZE,
            'opened_tab': request.GET.get('opened_tab'),
            'injection_not_rejected': admission.ucl_registration_complete != UCLRegistrationState.REJECTED.name
        }
    )
def admission_form(request, admission_id=None):
    admission = get_object_or_404(Admission, pk=admission_id) if admission_id else None
    if admission:
        can_access_admission(request.user, admission)
        if admission.is_draft():
            raise PermissionDenied
    selected_person = bool(request.POST.get('person_information', False))
    states = admission_state_choices.NEW_ADMIN_STATE[admission.state].get('choices', ()) if admission else None
    base_person = admission.person_information.person if admission else None
    base_person_form = PersonForm(
        data=request.POST or None,
        instance=base_person,
        selected_person=selected_person,
        no_first_name_checked=request.POST.get('no_first_name', False)
    )
    person_information = ContinuingEducationPerson.objects.filter(person=base_person).first()
    # TODO :: get last admission address if it exists instead of None
    address = admission.address if admission else None
    state = admission.state if admission else SUBMITTED
    adm_form = AdmissionForm(
        data=request.POST or None,
        user=request.user,
        instance=admission,
        initial={
            'state': state
        }
    )
    person_form = ContinuingEducationPersonForm(
        data=request.POST or None,
        instance=person_information,
        selected_person=selected_person
    )
    address_form = AddressForm(request.POST or None, instance=address)
    state = admission.state if admission else None
    if adm_form.is_valid() and person_form.is_valid() and address_form.is_valid() and base_person_form.is_valid():
        if address:
            address = address_form.save()
        else:
            address = Address(**address_form.cleaned_data)
            address.save()

        person = person_form.save(commit=False)
        base_person = base_person_form.save()
        person.person_id = base_person.pk
        person.save()

        admission = adm_form.save(commit=False)
        admission.address = address
        admission.billing_address = address
        admission.residence_address = address
        if not admission.person_information:
            admission.person_information = person
        if admission_id:
            admission.save()
        else:
            save_and_create_revision(get_revision_messages(ADMISSION_CREATION), admission, request.user)
        if admission.state == DRAFT:
            return redirect(reverse('admission'))
        return redirect(reverse('admission_detail', kwargs={'admission_id': admission.pk}))

    else:
        errors = list(itertools.product(adm_form.errors, person_form.errors, address_form.errors))
        display_errors(request, errors)

    return render(
        request,
        'admission_form.html',
        {
            'admission': admission,
            'admission_form': adm_form,
            'person_form': person_form,
            'address_form': address_form,
            'base_person_form': base_person_form,
            'state': state,
            'states': states,
            'selected_person': selected_person,
        }
    )