Пример #1
0
    def test_save_fr_bibliography_also_updates_en_bibliography(self, mock_update_or_create):
        """Ensure that if we modify bibliography in FR => bibliography in EN is updated with same text"""
        text_label_bibliography = TextLabelFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            label='bibliography'
        )
        cms_translated_text_fr = TranslatedTextFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=self.luys[self.current_ac.year].id,
            language='fr-be',
            text_label=text_label_bibliography,
            text='Some random text'
        )
        valid_form_data_fr = _get_valid_cms_form_data(cms_translated_text_fr)

        form = LearningUnitPedagogyEditForm(valid_form_data_fr)
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        for language in settings.LANGUAGES:
            mock_update_or_create.assert_any_call(
                entity=cms_translated_text_fr.entity,
                reference=cms_translated_text_fr.reference,
                language=language[0],
                text_label=cms_translated_text_fr.text_label,
                defaults={'text': cms_translated_text_fr.text}
            )
Пример #2
0
def edit_learning_unit_pedagogy(request, learning_unit_year_id, redirect_url):
    if request.method == 'POST':
        _post_learning_unit_pedagogy_form(request)
        return redirect(redirect_url)

    context = get_common_context_learning_unit_year(
        learning_unit_year_id, get_object_or_404(Person, user=request.user))
    label_name = request.GET.get('label')
    language = request.GET.get('language')
    text_lb = TextLabel.objects.prefetch_related(
        Prefetch('translatedtextlabel_set',
                 to_attr="translated_text_labels")).get(label=label_name)
    form = LearningUnitPedagogyEditForm(
        **{
            'learning_unit_year': context['learning_unit_year'],
            'language': language,
            'text_label': text_lb
        })
    form.load_initial()  # Load data from database
    context['form'] = form
    user_language = mdl.person.get_user_interface_language(request.user)
    context['text_label_translated'] = get_text_label_translated(
        text_lb, user_language)
    context['language_translated'] = find_language_in_settings(language)
    context['cms_label_pedagogy_fr_only'] = CMS_LABEL_PEDAGOGY_FR_ONLY
    context['label_name'] = label_name
    return render(request, "learning_unit/pedagogy_edit.html", context)
Пример #3
0
def _post_learning_unit_pedagogy_form(request):
    form = LearningUnitPedagogyEditForm(request.POST)
    if form.is_valid():
        form.save()
        last_academic_year_reported = form.luys[-1] if len(
            form.luys) >= 2 else None
        msg = build_success_message(last_academic_year_reported, form.luys[0])
        display_success_messages(request, msg)
Пример #4
0
 def test_save_without_postponement(self, mock_update_or_create):
     """In this test, we ensure that if we modify UE of N or N-... => The postponement is not done for CMS data"""
     form = LearningUnitPedagogyEditForm(self.valid_form_data)
     self.assertTrue(form.is_valid(), form.errors)
     form.save()
     mock_update_or_create.assert_called_once_with(entity=self.cms_translated_text.entity,
                                                   reference=self.cms_translated_text.reference,
                                                   language=self.cms_translated_text.language,
                                                   text_label=self.cms_translated_text.text_label,
                                                   defaults={'text': self.cms_translated_text.text})
Пример #5
0
def learning_unit_pedagogy_edit(request, learning_unit_year_id):
    if request.method == 'POST':
        form = LearningUnitPedagogyEditForm(request.POST)
        if form.is_valid():
            form.save()
        return HttpResponseRedirect(
            reverse("learning_unit_pedagogy",
                    kwargs={'learning_unit_year_id': learning_unit_year_id}))

    context = get_common_context_learning_unit_year(learning_unit_year_id)
    label_name = request.GET.get('label')
    language = request.GET.get('language')
    text_lb = text_label.find_root_by_name(label_name)
    form = LearningUnitPedagogyEditForm(
        **{
            'learning_unit_year': context['learning_unit_year'],
            'language': language,
            'text_label': text_lb
        })
    form.load_initial()  # Load data from database
    context['form'] = form

    user_language = mdl.person.get_user_interface_language(request.user)
    context['text_label_translated'] = next(
        (txt for txt in text_lb.translated_text_labels
         if txt.language == user_language), None)
    context['language_translated'] = next(
        (lang for lang in settings.LANGUAGES if lang[0] == language), None)
    return layout.render(request, "learning_unit/pedagogy_edit.html", context)
Пример #6
0
def summary_edit(request, learning_unit_year_id):
    if not is_summary_submission_opened():
        return redirect(reverse_lazy("outside_summary_submission_period"))

    learning_unit_year = get_object_or_404(LearningUnitYear,
                                           pk=learning_unit_year_id)
    if not can_access_summary(request.user, learning_unit_year):
        raise PermissionDenied("User is not summary responsible")

    if request.method == 'POST':
        form = LearningUnitPedagogyEditForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect("learning_unit_summary",
                        learning_unit_year_id=learning_unit_year_id)
    label_name = request.GET.get('label')
    lang = request.GET.get('language')
    text_lb = text_label.find_root_by_name(label_name)
    form = LearningUnitPedagogyEditForm(
        **{
            'learning_unit_year': learning_unit_year,
            'language': lang,
            'text_label': text_lb
        })
    form.load_initial()
    user_language = mdl.person.get_user_interface_language(request.user)
    text_label_translated = next((txt for txt in text_lb.translated_text_labels
                                  if txt.language == user_language), None)
    return layout.render(
        request, "my_osis/educational_information_edit.html", {
            "learning_unit_year": learning_unit_year,
            "form": form,
            "language_translated": find_language_in_settings(lang),
            "text_label_translated": text_label_translated
        })
Пример #7
0
def edit_learning_unit_pedagogy(request, learning_unit_year_id, redirect_url):
    if request.method == 'POST':
        form = LearningUnitPedagogyEditForm(request.POST)
        if form.is_valid():
            form.save()
        return redirect(redirect_url)
    context = get_common_context_learning_unit_year(
        learning_unit_year_id, get_object_or_404(Person, user=request.user))
    label_name = request.GET.get('label')
    language = request.GET.get('language')
    text_lb = text_label.find_root_by_name(label_name)
    form = LearningUnitPedagogyEditForm(
        **{
            'learning_unit_year': context['learning_unit_year'],
            'language': language,
            'text_label': text_lb
        })
    form.load_initial()  # Load data from database
    context['form'] = form
    user_language = mdl.person.get_user_interface_language(request.user)
    context['text_label_translated'] = next(
        (txt for txt in text_lb.translated_text_labels
         if txt.language == user_language), None)
    context['language_translated'] = find_language_in_settings(language)
    return layout.render(request, "learning_unit/pedagogy_edit.html", context)
Пример #8
0
    def test_save_with_postponement(self, mock_update_or_create):
        """In this test, we ensure that if we modify UE of N+1 or N+X => The postponement until the lastest UE"""
        luy_in_future = self.luys[self.current_ac.year + 1]
        cms_pedagogy_future = TranslatedTextFactory(
            entity=entity_name.LEARNING_UNIT_YEAR,
            reference=luy_in_future.id,
            language='EN',
            text='Text in future')
        form = LearningUnitPedagogyEditForm(
            data=_get_valid_cms_form_data(cms_pedagogy_future))
        self.assertTrue(form.is_valid(), form.errors)
        form.save()

        # N+1 ===> N+6
        self.assertEqual(mock_update_or_create.call_count, 5)
Пример #9
0
 def test_valid_form(self):
     form = LearningUnitPedagogyEditForm(self.valid_form_data)
     self.assertEqual(form.errors, {})
     self.assertTrue(form.is_valid())
Пример #10
0
 def test_invalid_form(self):
     del self.valid_form_data['cms_id']
     form = LearningUnitPedagogyEditForm(self.valid_form_data)
     self.assertFalse(form.is_valid())