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(): _save_form_and_display_messages(request, volume_edition_formset_container) return HttpResponseRedirect( reverse(learning_unit_components, args=[learning_unit_year_id])) 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)
def learning_unit_volumes_management(request, learning_unit_year_id, form_type): person = get_object_or_404(Person, user=request.user) context = get_common_context_learning_unit_year(learning_unit_year_id, person) context['learning_units'] = _get_learning_units_for_context(luy=context['learning_unit_year'], with_family=form_type == "full") volume_edition_formset_container = VolumeEditionFormsetContainer(request, context['learning_units'], person) if volume_edition_formset_container.is_valid() and not request.is_ajax(): _save_form_and_display_messages(request, volume_edition_formset_container) if form_type == "full": return HttpResponseRedirect(reverse(learning_unit_components, args=[learning_unit_year_id])) else: return HttpResponseRedirect(reverse("learning_unit", args=[learning_unit_year_id])) context['formsets'] = volume_edition_formset_container.formsets context['tab_active'] = 'components' context['entity_types_volume'] = REQUIREMENT_ENTITIES context['luy_url'] = 'learning_unit_components' if form_type == "full" else 'learning_unit' context['experimental_phase'] = True if request.is_ajax(): return JsonResponse({'errors': volume_edition_formset_container.errors}) return render(request, "learning_unit/volumes_management.html", context)
def test_post_volume_edition_formset_container__vol_tot_full_can_be_equal_to_partim( self): self.data_forms.update( get_valid_formset_data(self.learning_unit_year_partim.acronym)) volume_edition_formset_container = VolumeEditionFormsetContainer( self.request_factory.post(None, data=self.data_forms), self.learning_units_with_context, self.central_manager) self.assertTrue(volume_edition_formset_container.is_valid())
def test_post_volume_edition_formset_container(self): self.data_forms.update({ **get_valid_formset_data(self.learning_unit_year_partim.acronym, is_partim=True), 'postponement': 1 }) volume_edition_formset_container = VolumeEditionFormsetContainer( self.request_factory.post(None, data=self.data_forms), self.learning_units_with_context, self.central_manager) self.assertTrue(volume_edition_formset_container.is_valid()) volume_edition_formset_container.save()
def test_post_volume_edition_formset_container_wrong_vol_tot_full_must_be_greater_than_partim(self): request_factory = RequestFactory() data_forms = get_valid_formset_data(self.learning_unit_year_full.acronym) data_forms.update(get_valid_formset_data(self.learning_unit_year_partim.acronym)) volume_edition_formset_container = VolumeEditionFormsetContainer( request_factory.post(None, data=data_forms), self.learning_units_with_context, self.central_manager) self.assertFalse(volume_edition_formset_container.is_valid()) self.assertEqual( volume_edition_formset_container.formsets[self.learning_unit_year_partim].errors[0], {'volume_total': [_('vol_tot_full_must_be_greater_than_partim')]} )
def test_post_volume_edition_formset_container_wrong_vol_tot_full_must_be_greater_than_partim(self): request_factory = RequestFactory() data_forms = get_valid_formset_data(self.learning_unit_year_full.acronym) data_forms.update(get_valid_formset_data(self.learning_unit_year_partim.acronym)) data_forms.update({'LDROI1200A-0-volume_total': 3}) data_forms.update({'LDROI1200A-0-volume_q2': 3}) data_forms.update({'LDROI1200A-0-volume_requirement_entity': 2}) data_forms.update({'LDROI1200A-0-volume_total_requirement_entities': 3}) volume_edition_formset_container = VolumeEditionFormsetContainer( request_factory.post(None, data=data_forms), self.learning_units_with_context, self.central_manager) self.assertTrue(volume_edition_formset_container.is_valid()) # Volumes of partims can be greater than parent's
def test_post_volume_edition_formset_container(self): request_factory = RequestFactory() data_forms = get_valid_formset_data( self.learning_unit_year_full.acronym) data_forms.update( get_valid_formset_data(self.learning_unit_year_partim.acronym, is_partim=True)) volume_edition_formset_container = VolumeEditionFormsetContainer( request_factory.post(None, data=data_forms), self.learning_units_with_context, self.central_manager) self.assertTrue(volume_edition_formset_container.is_valid()) volume_edition_formset_container.save(1)
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)