Ejemplo n.º 1
0
def renew_applications(request):
    tutor = mdl_base.tutor.find_by_user(request.user)
    global_id = tutor.person.global_id
    post_data = dict(request.POST.lists())
    learning_container_year_acronyms = [param.split("_")[-1] for param, value in post_data.items()\
                                        if "learning_container_year_" in param]
    attributions_about_to_expired = attribution.get_attribution_list_about_to_expire(
        global_id=global_id)
    attribution_to_renew_list = [attrib for attrib in attributions_about_to_expired
                                 if attrib.get('acronym') in learning_container_year_acronyms and \
                                    attrib.get('is_renewable', False)]
    if not attribution_to_renew_list:
        messages.add_message(request, messages.ERROR,
                             _('no_attribution_renewed'))
        return redirect('applications_overview')

    l_containers_years = mdl_base.learning_container_year.search(id=[
        attrib.get('attribution_vacant', {}).get('learning_container_year_id')
        for attrib in attribution_to_renew_list
    ])

    for attri_to_renew in attribution_to_renew_list:
        learning_container_year = next(
            (l_containers_year for l_containers_year in l_containers_years
             if l_containers_year.acronym == attri_to_renew.get('acronym')),
            None)

        application_data = {
            'charge_lecturing_asked':
            attri_to_renew.get(learning_component_year_type.LECTURING),
            'charge_practical_asked':
            attri_to_renew.get(
                learning_component_year_type.PRACTICAL_EXERCISES),
        }
        form = ApplicationForm(learning_container_year=learning_container_year,
                               data=application_data)
        if form.is_valid():
            application = form.cleaned_data
            try:
                tutor_application.create_or_update_application(
                    global_id, application)
                tutor_application.set_pending_flag(
                    global_id, application,
                    tutor_application_epc.UPDATE_OPERATION)
                # Send signal to EPC
                tutor_application_epc.send_message(
                    tutor_application_epc.UPDATE_OPERATION, global_id,
                    application)
            except Exception as e:
                error_msg = "{}: {}".format(learning_container_year.acronym,
                                            e.args[0])
                messages.add_message(request, messages.ERROR, error_msg)
    return redirect('applications_overview')
Ejemplo n.º 2
0
def create_or_update_application(request, learning_container_year_id):
    tutor = mdl_base.tutor.find_by_user(request.user)
    global_id = tutor.person.global_id
    learning_unit_year = mdl_base.learning_unit_year.get_full_by_learning_container_year_id(
        learning_container_year_id)
    learning_container_year = learning_unit_year.learning_container_year
    can_be_saved = True

    if request.method == 'POST':
        form = ApplicationForm(learning_container_year=learning_container_year,
                               data=request.POST)
        if form.is_valid():
            application = form.cleaned_data
            try:
                tutor_application.create_or_update_application(
                    global_id, application)
                tutor_application.set_pending_flag(
                    global_id, application,
                    tutor_application_epc.UPDATE_OPERATION)
                # Send message to EPC
                tutor_application_epc.send_message(
                    tutor_application_epc.UPDATE_OPERATION, global_id,
                    application)
            except Exception as e:
                error_msg = e.args[0]
                messages.add_message(request, messages.ERROR, error_msg)
            return redirect('applications_overview')
    else:
        inital_data = tutor_application.get_application(
            global_id, learning_container_year)
        can_be_saved = tutor_application.can_be_updated(
            inital_data) if inital_data else True
        form = ApplicationForm(
            initial=inital_data,
            learning_container_year=learning_container_year,
        )

    return layout.render(
        request, "application_form.html", {
            'a_tutor': tutor,
            'form': form,
            'learning_container_year': learning_container_year,
            'learning_unit_year': learning_unit_year,
            'can_be_saved': can_be_saved
        })
Ejemplo n.º 3
0
def delete_application(request, learning_container_year_id):
    tutor = mdl_base.tutor.find_by_user(request.user)
    global_id = tutor.person.global_id
    learning_container_year = mdl_base.learning_container_year.find_by_id(learning_container_year_id)

    application_to_delete = tutor_application.get_application(global_id, learning_container_year)
    if application_to_delete:
         try:
            # Delete with FLAG Pending
            tutor_application.set_pending_flag(global_id, application_to_delete,
                                               tutor_application_epc.DELETE_OPERATION)
            # Send signal to EPC
            tutor_application_epc.send_message(tutor_application_epc.DELETE_OPERATION,
                                               global_id,
                                               application_to_delete)
         except Exception as e:
            error_msg = e.args[0]
            messages.add_message(request, messages.ERROR, error_msg)
         return redirect('applications_overview')
    raise Http404