Exemple #1
0
def update_learning_unit(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear, pk=learning_unit_year_id)
    person = get_object_or_404(Person, user=request.user)

    learning_unit_full_instance = None
    if learning_unit_year.subtype == learning_unit_year_subtypes.PARTIM:
        learning_unit_full_instance = learning_unit_year.parent.learning_unit

    # TODO :: clean code ; end_postponement could be removed from kwargs in this following
    # LearningUnitPostponementForm instantiation + in the template form
    end_postponement = learning_unit_year.academic_year if not bool(int(request.POST.get('postponement', 1))) else None
    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=learning_unit_year.academic_year,
        end_postponement=end_postponement,
        learning_unit_instance=learning_unit_year.learning_unit,
        learning_unit_full_instance=learning_unit_full_instance,
        data=request.POST or None,
        external=learning_unit_year.is_external(),
    )

    if postponement_form.is_valid():
        # Update current learning unit year
        _save_form_and_display_messages(request, postponement_form)
        return redirect('learning_unit', learning_unit_year_id=learning_unit_year_id)

    context = postponement_form.get_context()
    context["learning_unit_year"] = learning_unit_year
    context["is_update"] = True
    template = 'learning_unit/simple/update.html'

    return render(request, template, context)
Exemple #2
0
def create_learning_unit(request, academic_year_id):
    person = get_object_or_404(Person, user=request.user)
    if request.POST.get('academic_year'):
        academic_year_id = request.POST.get('academic_year')

    academic_year = get_object_or_404(AcademicYear, pk=academic_year_id)
    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=academic_year,
        data=request.POST or None)
    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    return render(request, "learning_unit/simple/creation.html",
                  postponement_form.get_context())
Exemple #3
0
def create_partim_form(request, learning_unit_year_id):
    person = get_object_or_404(Person, user=request.user)
    learning_unit_year_full = get_object_or_404(LearningUnitYear,
                                                pk=learning_unit_year_id)

    postponement_form = LearningUnitPostponementForm(
        person=person,
        learning_unit_full_instance=learning_unit_year_full.learning_unit,
        start_postponement=learning_unit_year_full.academic_year,
        data=request.POST or None)

    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    context = postponement_form.get_context()
    context.update({'learning_unit_year': learning_unit_year_full})

    return render(request, "learning_unit/simple/creation_partim.html",
                  context)
Exemple #4
0
def get_external_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)

    if request.POST.get('academic_year'):
        academic_year = request.POST.get('academic_year')

    academic_year = get_object_or_404(AcademicYear, pk=academic_year)

    postponement_form = LearningUnitPostponementForm(
        person=person,
        start_postponement=academic_year,
        data=request.POST or None,
        external=True,
    )

    if postponement_form.is_valid():
        return _save_and_redirect(postponement_form, request)

    return render(request, "learning_unit/external/create.html", postponement_form.get_context())