Ejemplo n.º 1
0
def read_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 = is_eligible_to_update_learning_unit_pedagogy(
        learning_unit_year, person)
    user_language = mdl.person.get_user_interface_language(request.user)
    context['cms_labels_translated'] = get_cms_label_data(
        CMS_LABEL_PEDAGOGY, user_language)
    context['form_french'] = LearningUnitPedagogyForm(
        learning_unit_year=learning_unit_year,
        language_code=settings.LANGUAGE_CODE_FR)
    context['form_english'] = LearningUnitPedagogyForm(
        learning_unit_year=learning_unit_year,
        language_code=settings.LANGUAGE_CODE_EN)
    context[
        'teaching_materials'] = teaching_material.find_by_learning_unit_year(
            learning_unit_year)
    context['can_edit_information'] = perm_to_edit
    context[
        'can_edit_summary_locked_field'] = perms.can_edit_summary_locked_field(
            learning_unit_year, person)
    context[
        'summary_responsibles'] = find_all_summary_responsibles_by_learning_unit_year(
            learning_unit_year)
    context['other_teachers'] = get_no_summary_responsible_teachers(
        learning_unit_year, context['summary_responsibles'])
    context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY
    return render(request, template, context)
Ejemplo n.º 2
0
def read_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 = is_eligible_to_update_learning_unit_pedagogy(
        learning_unit_year, person)
    user_language = mdl.person.get_user_interface_language(request.user)

    translated_labels_with_text = TranslatedTextLabel.objects.filter(
        language=user_language,
        text_label__label__in=CMS_LABEL_PEDAGOGY).prefetch_related(
            Prefetch("text_label__translatedtext_set",
                     queryset=TranslatedText.objects.filter(
                         language=settings.LANGUAGE_CODE_FR,
                         entity=LEARNING_UNIT_YEAR,
                         reference=learning_unit_year_id),
                     to_attr="text_fr"),
            Prefetch(
                "text_label__translatedtext_set",
                queryset=TranslatedText.objects.filter(
                    language=settings.LANGUAGE_CODE_EN,
                    entity=LEARNING_UNIT_YEAR,
                    reference=learning_unit_year_id),
                to_attr="text_en")).annotate(
                    label_ordering=Case(*[
                        When(text_label__label=label, then=Value(i))
                        for i, label in enumerate(CMS_LABEL_PEDAGOGY)
                    ],
                                        default=Value(len(CMS_LABEL_PEDAGOGY)),
                                        output_field=IntegerField())
                ).select_related("text_label").order_by("label_ordering")
    teaching_materials = TeachingMaterial.objects.filter(
        learning_unit_year=learning_unit_year).order_by('order')
    attributions = Attribution.objects.filter(
        learning_unit_year=learning_unit_year).select_related(
            "tutor__person").order_by("tutor__person")

    translated_text_ids = itertools.chain.from_iterable(
        (*translated_label.text_label.text_fr,
         *translated_label.text_label.text_en)
        for translated_label in translated_labels_with_text)

    reversion = Version.objects.filter(
        Q(content_type=ContentType.objects.get_for_model(TranslatedText),
          object_id__in=map(lambda obj: obj.id, translated_text_ids))
        | Q(content_type=ContentType.objects.get_for_model(TeachingMaterial),
            object_id__in=map(lambda obj: obj.id, teaching_materials))
    ).select_related("revision", "revision__user").prefetch_related(
        Prefetch(
            "revision__user__person",
            to_attr="author")).order_by("-revision__date_created").first()

    context['cms_labels_translated'] = translated_labels_with_text
    context['teaching_materials'] = teaching_materials
    context['can_edit_information'] = perm_to_edit
    context[
        'can_edit_summary_locked_field'] = perms.can_edit_summary_locked_field(
            learning_unit_year, person)
    context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY
    context['attributions'] = attributions
    context["version"] = reversion
    return render(request, template, context)
Ejemplo n.º 3
0
 def test_is_eligible_to_update_learning_pedagogy_after_2017(self):
     self.luy.academic_year = AcademicYearFactory(year=2019)
     self.assertTrue(
         is_eligible_to_update_learning_unit_pedagogy(
             self.luy, self.central_manager))
Ejemplo n.º 4
0
 def test_is_not_eligible_to_update_learning_pedagogy_cause_before_2018(
         self):
     self.luy.academic_year = AcademicYearFactory(year=2015)
     self.assertFalse(
         is_eligible_to_update_learning_unit_pedagogy(
             self.luy, self.central_manager))