Ejemplo n.º 1
0
    def apply_learning_unit_year_postponement(self, request, queryset):
        # Potential circular imports
        from base.business.learning_units.automatic_postponement import LearningUnitAutomaticPostponementToN6
        from base.views.common import display_success_messages, display_error_messages

        result, errors = LearningUnitAutomaticPostponementToN6(queryset).postpone()
        count = len(result)
        display_success_messages(
            request, ngettext(
                '%(count)d learning unit has been postponed with success',
                '%(count)d learning units have been postponed with success', count
            ) % {'count': count}
        )
        if errors:
            display_error_messages(request, "{} : {}".format(
                _("The following learning units ended with error"),
                ", ".join([str(error) for error in errors])
            ))
Ejemplo n.º 2
0
    def apply_learning_unit_year_postponement(self, request, queryset):
        # Potential circular imports
        from base.business.learning_units.automatic_postponement import LearningUnitAutomaticPostponement
        from base.views.common import display_success_messages, display_error_messages

        result, errors = LearningUnitAutomaticPostponement(queryset).postpone()
        count = len(result)
        display_success_messages(
            request,
            ngettext(
                '%(count)d learning unit has been postponed with success',
                '%(count)d learning units have been postponed with success',
                count) % {'count': count})
        if errors:
            display_error_messages(
                request, "{} : {}".format(
                    _("The following learning units ended with error"),
                    ", ".join([str(error) for error in errors])))
Ejemplo n.º 3
0
def add_continuing_education_training_manager(request):
    errors = []
    person_training_form = PersonTrainingForm(request.POST or None)
    if person_training_form.is_valid():
        person = person_training_form.cleaned_data['person']
        _append_user_to_training_managers(person.user)
        person_training_form.save()
        success_msg = _(
            'Successfully assigned %(manager)s to the training %(training)s'
        ) % {
            "manager": person,
            "training": person_training_form.cleaned_data['training'].acronym
        }
        display_success_messages(request, success_msg)
    else:
        errors.append(person_training_form.errors)
        display_errors(request, errors)
    return redirect(list_managers)
Ejemplo n.º 4
0
    def copy_reddot_data(self, request, queryset):
        # Potential circular imports
        from base.business.education_groups.automatic_postponement import ReddotEducationGroupAutomaticPostponement
        from base.views.common import display_success_messages, display_error_messages

        result, errors = ReddotEducationGroupAutomaticPostponement(queryset).postpone()
        count = len(result)
        display_success_messages(
            request, ngettext(
                "%(count)d education group has been updated with success.",
                "%(count)d education groups have been updated with success.", count
            ) % {'count': count}
        )
        if errors:
            display_error_messages(request, "{} : {}".format(
                _("The following education groups ended with error"),
                ", ".join([str(error) for error in errors])
            ))
Ejemplo n.º 5
0
    def post(self, request, **kwargs):
        try:
            postponer = PostponeContent(self.get_root().previous_year())
            postponer.postpone()
            count = len(postponer.result)
            success = ngettext(
                "%(count)d education group has been postponed with success.",
                "%(count)d education groups have been postponed with success.",
                count) % {
                    'count': count
                }
            display_success_messages(request, success)
        except NotPostponeError as e:
            display_error_messages(request, str(e))

        return redirect(
            reverse(
                "education_group_read",
                args=[kwargs["root_id"], kwargs["education_group_year_id"]]))
Ejemplo n.º 6
0
def _common_success_redirect(request, form, parent=None):
    education_group_year = form.save()
    parent_id = parent.pk if parent else education_group_year.pk

    success_msg = [
        _get_success_message_for_creation_education_group_year(
            parent_id, education_group_year)
    ]
    if hasattr(form, 'education_group_year_postponed'):
        success_msg += [
            _get_success_message_for_creation_education_group_year(
                egy.id, egy) for egy in form.education_group_year_postponed
        ]
    display_success_messages(request, success_msg, extra_tags='safe')

    # Redirect
    url = reverse("education_group_read",
                  args=[parent_id, education_group_year.pk])
    return redirect(url)
Ejemplo n.º 7
0
    def apply_education_group_year_postponement(self, request, queryset):
        # Potential circular imports
        from base.business.education_groups.automatic_postponement import EducationGroupAutomaticPostponement
        from base.views.common import display_success_messages, display_error_messages

        result, errors = EducationGroupAutomaticPostponement(
            queryset).postpone()
        count = len(result)
        display_success_messages(
            request,
            ngettext(
                "%(count)d education group has been postponed with success.",
                "%(count)d education groups have been postponed with success.",
                count) % {'count': count})
        if errors:
            display_error_messages(
                request, "{} : {}".format(
                    _("The following education groups ended with error"),
                    ", ".join([str(error) for error in errors])))
Ejemplo n.º 8
0
def entity_read(request, entity_version_id):
    entity_version = get_object_or_404(EntityVersion, id=entity_version_id)
    can_user_post = can_user_edit_educational_information_submission_dates_for_entity(request.user,
                                                                                      entity_version.entity)
    if request.method == "POST" and not can_user_post:
        logger.warning("User {} has no sufficient right to modify submission dates of educational information.".
                       format(request.user))
        raise PermissionDenied()

    entity_parent = entity_version.get_parent_version()
    descendants = entity_version.descendants

    form = EntityCalendarEducationalInformationForm(entity_version, request.POST or None)
    if form.is_valid():
        display_success_messages(request, _("Educational information submission dates updated"))
        form.save_entity_calendar(entity_version.entity)

    # TODO Remove locals
    return render(request, "entity/identification.html", locals())
Ejemplo n.º 9
0
def update_learning_unit_pedagogy(request, learning_unit_year_id, context,
                                  template):
    person = get_object_or_404(Person, user=request.user)
    context.update(
        get_common_context_learning_unit_year(learning_unit_year_id, person))
    learning_unit_year = context['learning_unit_year']
    perm_to_edit = int(request.user.has_perm('can_edit_learningunit_pedagogy'))

    post = request.POST or None
    summary_form = SummaryModelForm(post,
                                    person,
                                    context['is_person_linked_to_entity'],
                                    instance=learning_unit_year)
    BibliographyFormset = inlineformset_factory(LearningUnitYear,
                                                Bibliography,
                                                fields=('title', 'mandatory'),
                                                max_num=10,
                                                extra=perm_to_edit,
                                                form=BibliographyModelForm,
                                                can_delete=perm_to_edit)
    bibliography_formset = BibliographyFormset(post,
                                               instance=learning_unit_year,
                                               form_kwargs={'person': person})

    if perm_to_edit and summary_form.is_valid(
    ) and bibliography_formset.is_valid():
        try:
            summary_form.save()
            bibliography_formset.save()

            display_success_messages(request,
                                     _("success_modification_learning_unit"))
            # Redirection on the same page
            return HttpResponseRedirect(request.path_info)

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

    context.update(get_cms_pedagogy_form(request, learning_unit_year))
    context['summary_editable_form'] = summary_form
    context['bibliography_formset'] = bibliography_formset
    return layout.render(request, template, context)
Ejemplo n.º 10
0
def _update_proposal(request, user_person, proposal):
    initial_data = compute_form_initial_data(proposal.learning_unit_year)
    initial_data.update(_build_proposal_data(proposal))

    # Workaround Set initial data from proposal initial data json to compute effectively data modified
    # and compute proposal type
    initial_data_from_json = compute_form_initial_data_from_proposal_json(
        proposal.initial_data)
    initial_data_from_json.update(_build_proposal_data(proposal))

    proposal_form = LearningUnitProposalModificationForm(
        request.POST or None,
        initial=initial_data_from_json,
        instance=proposal,
        learning_unit=proposal.learning_unit_year.learning_unit,
        person=user_person)

    if proposal_form.is_valid():
        try:
            changed_fields = proposal_form.changed_data_for_fields_that_can_be_modified
            type_proposal = business_proposal.compute_proposal_type(
                changed_fields, initial_data_from_json.get("type"))
            proposal_form.save(proposal.learning_unit_year, type_proposal,
                               proposal_form.cleaned_data.get("state"))
            display_success_messages(request,
                                     _("proposal_edited_successfully"))
            return HttpResponseRedirect(
                reverse('learning_unit',
                        args=[proposal.learning_unit_year.id]))
        except (IntegrityError, ValueError) as e:
            display_error_messages(request, e.args[0])

    proposal_form.initial = initial_data

    return layout.render(
        request, 'learning_unit/proposal/update_modification.html', {
            'learning_unit_year': proposal.learning_unit_year,
            'person': user_person,
            'form': proposal_form,
            'experimental_phase': True
        })
def _display_adapted_ucl_registration_message(admission, request):
    if admission.ucl_registration_complete == UCLRegistrationState.SENDED.name:
        display_warning_messages(request, _('Folder sended to EPC : waiting for response'))
    elif admission.ucl_registration_complete == UCLRegistrationState.REJECTED.name:
        display_error_messages(
            request,
            _('Folder injection into EPC failed : %(reasons)s') % {
                'reasons': admission.get_ucl_registration_error_display()
            }
        )
    elif admission.ucl_registration_complete == UCLRegistrationState.DEMANDE.name:
        display_info_messages(request, _('Folder injection into EPC succeeded : UCLouvain registration on demand'))
    elif admission.ucl_registration_complete == UCLRegistrationState.INSCRIT.name:
        display_success_messages(request, _('Folder injection into EPC succeeded : UCLouvain registration completed'))
    elif admission.ucl_registration_complete != UCLRegistrationState.INIT_STATE.name:
        display_info_messages(
            request,
            _('Folder injection into EPC succeeded : UCLouvain registration status : %(status)s') % {
                'status': admission.get_ucl_registration_complete_display()
            }
        )
Ejemplo n.º 12
0
def get_proposal_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)
    academic_year_pk = request.POST.get('academic_year', academic_year)
    academic_year = get_object_or_404(AcademicYear, pk=academic_year_pk)

    proposal_form = CreationProposalBaseForm(request.POST or None, person, academic_year)
    if request.method == 'POST':
        if proposal_form.is_valid():
            proposal = proposal_form.save()
            success_msg = _(
                "Proposal learning unit <a href='%(link)s'> %(acronym)s (%(academic_year)s) </a> successfuly created.")\
                % {
                    'link': reverse("learning_unit", kwargs={'learning_unit_year_id': proposal.learning_unit_year.id}),
                    'acronym': proposal.learning_unit_year.acronym,
                    'academic_year': proposal.learning_unit_year.academic_year
                }
            display_success_messages(request, success_msg, extra_tags='safe')
            return redirect('learning_unit', learning_unit_year_id=proposal.learning_unit_year.pk)
        else:
            show_error_message_for_form_invalid(request)

    return render(request, "learning_unit/proposal/creation.html", proposal_form.get_context())
Ejemplo n.º 13
0
def publish(request, education_group_year_id, root_id):
    education_group_year = get_object_or_404(EducationGroupYear,
                                             pk=education_group_year_id)

    try:
        general_information.publish(education_group_year)
        message = _("The program %(acronym)s will be published soon") % {
            'acronym': education_group_year.acronym
        }
        display_success_messages(request, message, extra_tags='safe')
    except PublishException as e:
        display_error_messages(request, str(e))

    default_redirect_view = reverse('education_group_general_informations',
                                    kwargs={
                                        'root_id':
                                        root_id,
                                        'education_group_year_id':
                                        education_group_year_id
                                    })
    return HttpResponseRedirect(
        request.META.get('HTTP_REFERER', default_redirect_view))
Ejemplo n.º 14
0
    def post(self, request, **kwargs):
        try:
            postponer = PostponeContent(self.root.previous_year())
            postponer.postpone()
            success = _(
                "%(count_elements)s OF(s) and %(count_links)s link(s) have been postponed with success."
            ) % {
                'count_elements': postponer.number_elements_created,
                'count_links': postponer.number_links_created
            }
            display_success_messages(request, success)
            display_warning_messages(request, postponer.warnings)

        except NotPostponeError as e:
            display_error_messages(request, str(e))

        return JsonResponse({
            'success_url':
            reverse(
                "education_group_read",
                args=[kwargs["root_id"], kwargs["education_group_year_id"]])
        })
Ejemplo n.º 15
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 = LearningUnitEndDateForm(request.POST or None, learning_unit_year=learning_unit_year)
    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)
Ejemplo n.º 16
0
def _update_or_create_proposal(request, learning_unit_year, proposal=None):
    person = get_object_or_404(Person, user=request.user)

    proposal_base_form = ProposalBaseForm(request.POST or None, person,
                                          learning_unit_year, proposal)

    if proposal_base_form.is_valid():
        proposal = proposal_base_form.save()
        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 = proposal_base_form.get_context()
    if proposal:
        return render(request,
                      'learning_unit/proposal/update_modification.html',
                      context)
    return render(request, 'learning_unit/proposal/create_modification.html',
                  context)
Ejemplo n.º 17
0
def list_managers(request):
    search_form = ManagerFilterForm(data=request.GET)
    person_training_form = PersonTrainingForm(request.POST or None)
    trainings = ContinuingEducationTraining.objects.all().select_related(
        'education_group')

    if search_form.is_valid():
        managers = search_form.get_managers()
    else:
        managers = Person.objects.filter(
            user__groups__name=TRAINING_MANAGERS_GROUP).order_by('last_name')

    errors = []
    if person_training_form.is_valid():
        person = person_training_form.cleaned_data['person']
        _append_user_to_training_managers(person.user)
        person_training_form.save()
        success_msg = _(
            'Successfully assigned %(manager)s to the training %(training)s'
        ) % {
            "manager": person,
            "training": person_training_form.cleaned_data['training'].acronym
        }
        display_success_messages(request, success_msg)
    else:
        errors.append(person_training_form.errors)
        display_errors(request, errors)

    for manager in managers:
        manager.trainings = trainings.filter(managers=manager).distinct()

    return render(
        request, "managers.html", {
            'managers': get_object_list(request, managers),
            'search_form': search_form,
            'person_training_form': person_training_form
        })
Ejemplo n.º 18
0
def learning_unit_modification_proposal(request, learning_unit_year_id):
    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           id=learning_unit_year_id)
    user_person = get_object_or_404(Person, user=request.user)
    initial_data = compute_form_initial_data(learning_unit_year)
    proposal = proposal_learning_unit.find_by_learning_unit_year(
        learning_unit_year)

    form = LearningUnitProposalModificationForm(
        request.POST or None,
        initial=initial_data,
        instance=proposal,
        learning_unit=learning_unit_year.learning_unit,
        person=user_person)

    if form.is_valid():
        type_proposal = business_proposal.compute_proposal_type(
            form.changed_data_for_fields_that_can_be_modified,
            initial_data.get("type"))
        form.save(learning_unit_year, type_proposal,
                  compute_proposal_state(user_person))

        display_success_messages(
            request,
            _("success_modification_proposal").format(
                _(type_proposal), learning_unit_year.acronym))

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

    return layout.render(
        request, 'learning_unit/proposal/create_modification.html', {
            'learning_unit_year': learning_unit_year,
            'person': user_person,
            'form': form,
            'experimental_phase': True
        })
Ejemplo n.º 19
0
def learning_unit_volumes_management(request, learning_unit_year_id):
    person = get_object_or_404(Person, user=request.user)
    context = get_common_context_learning_unit_year(learning_unit_year_id,
                                                    person)

    context[
        'learning_units'] = learning_unit_year_with_context.get_with_context(
            learning_container_year_id=context['learning_unit_year'].
            learning_container_year_id)

    volume_edition_formset_container = VolumeEditionFormsetContainer(
        request, context['learning_units'], person)

    if volume_edition_formset_container.is_valid() and not request.is_ajax():
        try:
            postponement = int(request.POST.get('postponement', 1))
            volume_edition_formset_container.save(postponement)
            display_success_messages(request,
                                     _('success_modification_learning_unit'))
            return HttpResponseRedirect(
                reverse(learning_unit_components,
                        args=[learning_unit_year_id]))

        except IntegrityError:
            display_error_messages(request,
                                   _("error_modification_learning_unit"))

    context['formsets'] = volume_edition_formset_container.formsets
    context['tab_active'] = 'components'
    context['experimental_phase'] = True

    if request.is_ajax():
        return JsonResponse(
            {'errors': volume_edition_formset_container.errors})

    return layout.render(request, "learning_unit/volumes_management.html",
                         context)
Ejemplo n.º 20
0
def modify_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)
    initial_data = compute_learning_unit_modification_form_initial_data(
        learning_unit_year)
    form = LearningUnitModificationForm(
        request.POST or None,
        learning_unit_year_instance=learning_unit_year,
        person=person,
        initial=initial_data)
    if form.is_valid():
        entities_data = form.get_entities_data()
        lu_type_full_data = form.get_data_for_learning_unit()

        try:
            postponement = bool(int(request.POST.get('postponement', 1)))

            update_learning_unit_year_with_report(learning_unit_year,
                                                  lu_type_full_data,
                                                  postponement)
            update_learning_unit_year_entities_with_report(
                learning_unit_year, entities_data, postponement)

            display_success_messages(request,
                                     _("success_modification_learning_unit"))

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

        except IntegrityError:
            display_error_messages(request,
                                   _("error_modification_learning_unit"))

    context = {"learning_unit_year": learning_unit_year, "form": form}
    return layout.render(request, 'learning_unit/modification.html', context)
Ejemplo n.º 21
0
def _save_form_and_display_messages(request, form, learning_unit_year):
    records = None
    existing_proposal = ProposalLearningUnit.objects.filter(
        learning_unit_year__learning_unit=learning_unit_year.learning_unit
    ).order_by('learning_unit_year__academic_year__year')
    try:
        records = form.save()
        display_warning_messages(request, getattr(form, 'warnings', []))

        is_postponement = bool(int(request.POST.get('postponement', 0)))

        if is_postponement and existing_proposal:
            display_success_messages(
                request,
                _('The learning unit has been updated (the report has not been done from %(year)s because the learning '
                  'unit is in proposal).') % {
                      'year':
                      existing_proposal[0].learning_unit_year.academic_year
                  })
        elif is_postponement:
            display_success_messages(
                request,
                _('The learning unit has been updated (with report).'))
        else:
            display_success_messages(
                request,
                _('The learning unit has been updated (without report).'))

    except ConsistencyError as e:
        error_list = e.error_list
        error_list.insert(
            0,
            _('The learning unit has been updated until %(year)s.') %
            {'year': e.last_instance_updated.academic_year})
        display_error_messages(request, e.error_list)
    return records
Ejemplo n.º 22
0
 def delete(self, request, *args, **kwargs):
     for education_group_year in delete.get_education_group_years_to_delete(
             self.get_object()):
         delete.start(education_group_year)
     common.display_success_messages(request, self.success_message)
     return JsonResponse({'success': True, 'success_url': self.success_url})
def _set_success_message(request, is_plural, received_file_state=True):
    success_msg = "{} {}".format(
        _('Files are now mark as ')
        if is_plural else _('File is now mark as '),
        _('received') if received_file_state else _('not received'))
    display_success_messages(request, success_msg)
Ejemplo n.º 24
0
def _show_import_success_message(request, period):
    display_success_messages(
        request,
        _('Internships ratings successfully imported for period %(period)s') %
        {'period': period})
Ejemplo n.º 25
0
def toggle_summary_locked(request, learning_unit_year_id):
    luy = learning_unit_year.toggle_summary_locked(learning_unit_year_id)
    success_msg = "Update for teacher locked" if luy.summary_locked else "Update for teacher unlocked"
    display_success_messages(request, success_msg)
    return redirect(reverse("learning_unit_pedagogy", kwargs={'learning_unit_year_id': learning_unit_year_id}))
Ejemplo n.º 26
0
def _show_reminder_sent_error_message(request):
    display_success_messages(request,
                             _('An error occured while sending reminders'))
Ejemplo n.º 27
0
def show_success_learning_unit_year_creation_message(
        request, learning_unit_year_created):
    success_msg = create_learning_unit_year_creation_message(
        learning_unit_year_created)
    display_success_messages(request, success_msg, extra_tags='safe')
Ejemplo n.º 28
0
def _set_success_message(request, is_plural, admission_archived=True):
    success_msg = "{} {}".format(
        _('Files are now') if is_plural else _('File is now'),
        _('archived') if admission_archived else _('unarchived'))
    display_success_messages(request, success_msg)
Ejemplo n.º 29
0
def _down(request, group_element_year, *args, **kwargs):
    success_msg = _("The %(acronym)s has been moved") % {
        'acronym': group_element_year.child
    }
    group_element_year.down()
    display_success_messages(request, success_msg)
Ejemplo n.º 30
0
def _save_and_redirect(request, form, learning_unit_year, success_url):
    form.save(learning_unit_year=learning_unit_year)
    display_success_messages(request, "Teaching materials has been updated")
    return redirect(success_url)
Ejemplo n.º 31
0
 def delete(self, request, *args, **kwargs):
     result = super().delete(request, *args, **kwargs)
     common.display_success_messages(request, _(self.success_message))
     return result
Ejemplo n.º 32
0
def _show_reminder_sent_success_message(request):
    display_success_messages(request,
                             _('Summaries have been sent successfully'))