Example #1
0
def learning_unit_edition_end_date(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)

    context = get_learning_unit_identification_context(learning_unit_year_id,
                                                       person)

    learning_unit_to_edit = learning_unit_year.learning_unit
    form = LearningUnitDailyManagementEndDateForm(
        request.POST or None,
        learning_unit_year=learning_unit_year,
        person=person)
    if form.is_valid():
        try:
            result = form.save()
            display_success_messages(request, result, extra_tags='safe')

            learning_unit_year_id = _get_current_learning_unit_year_id(
                learning_unit_to_edit, learning_unit_year_id)

            return HttpResponseRedirect(
                reverse('learning_unit', args=[learning_unit_year_id]))

        except IntegrityError as e:
            display_error_messages(request, e.args[0])

    context['form'] = form
    return render(request, 'learning_unit/simple/update_end_date.html',
                  context)
Example #2
0
def _update_or_create_suppression_proposal(request,
                                           learning_unit_year,
                                           proposal=None):
    person = get_object_or_404(Person, user=request.user)

    proposal_type = ProposalType.SUPPRESSION.name
    initial = _get_initial(learning_unit_year,
                           proposal,
                           person,
                           proposal_type=proposal_type)

    max_year = _get_max_year(learning_unit_year, proposal)

    form_end_date = LearningUnitProposalEndDateForm(request.POST or None,
                                                    learning_unit_year,
                                                    max_year=max_year,
                                                    person=person)
    form_proposal = ProposalLearningUnitForm(request.POST or None,
                                             person=person,
                                             instance=proposal,
                                             initial=initial)

    if request.method == 'POST':
        if form_end_date.is_valid() and form_proposal.is_valid():
            with transaction.atomic():
                form_proposal.save()

                # For the proposal, we do not update learning_unit_year
                form_end_date.save(update_learning_unit_year=False)

                display_success_messages(
                    request,
                    _("You proposed a modification of type %(type)s for the learning unit %(acronym)s."
                      ) % {
                          'type': ProposalType.SUPPRESSION.value,
                          'acronym': learning_unit_year.acronym
                      })

            return redirect('learning_unit',
                            learning_unit_year_id=learning_unit_year.id)
        else:
            show_error_message_for_form_invalid(request)

    context = get_learning_unit_identification_context(learning_unit_year.id,
                                                       person)
    context.update({
        'person': person,
        'form_end_date': form_end_date,
        'form_proposal': form_proposal,
    })

    if proposal:
        return render(request,
                      'learning_unit/proposal/update_suppression.html',
                      context)
    return render(request, 'learning_unit/proposal/create_suppression.html',
                  context)
Example #3
0
def _update_or_create_suppression_proposal(request,
                                           learning_unit_year,
                                           proposal=None):
    person = get_object_or_404(Person, user=request.user)

    proposal_type = ProposalType.SUPPRESSION.name
    initial = _get_initial(learning_unit_year,
                           proposal,
                           person,
                           proposal_type=proposal_type)

    max_year = _get_max_year(learning_unit_year, proposal)

    form_end_date = LearningUnitEndDateForm(request.POST or None,
                                            learning_unit_year,
                                            max_year=max_year)
    form_proposal = ProposalLearningUnitForm(request.POST or None,
                                             person=person,
                                             instance=proposal,
                                             initial=initial)

    if form_end_date.is_valid() and form_proposal.is_valid():
        with transaction.atomic():
            form_proposal.save()

            # For the proposal, we do not update learning_unit_year
            form_end_date.save(update_learning_unit_year=False)

            display_success_messages(
                request,
                _("You proposed a modification of type {} for the learning unit {}."
                  ).format(_(proposal_type), learning_unit_year.acronym))

        return redirect('learning_unit',
                        learning_unit_year_id=learning_unit_year.id)

    context = get_learning_unit_identification_context(learning_unit_year.id,
                                                       person)
    context.update({
        'person': person,
        'form_end_date': form_end_date,
        'form_proposal': form_proposal,
        'experimental_phase': True
    })

    if learning_unit_year.get_partims_related().exists():
        display_warning_messages(request, _("The learning unit have partim"))

    if proposal:
        return render(request,
                      'learning_unit/proposal/update_suppression.html',
                      context)
    return render(request, 'learning_unit/proposal/create_suppression.html',
                  context)
Example #4
0
def learning_unit_identification(request, learning_unit_year_id):
    person = get_object_or_404(Person, user=request.user)
    context = get_learning_unit_identification_context(learning_unit_year_id,
                                                       person)

    learning_unit_year = context['learning_unit_year']

    if learning_unit_year.is_external():
        template = "learning_unit/external/read.html"
        permission = 'base.can_access_externallearningunityear'
    else:
        template = "learning_unit/identification.html"
        permission = 'base.can_access_learningunit'

    if not person.user.has_perm(permission):
        raise PermissionDenied
    return layout.render(request, template, context)