def learning_unit_year_add(request): person = get_object_or_404(Person, user=request.user) form = CreateLearningUnitYearForm(person, request.POST) if form.is_valid(): data = form.cleaned_data starting_academic_year = mdl.academic_year.starting_academic_year() academic_year = data['academic_year'] year = academic_year.year status = data['status'] == 'on' additional_entity_version_1 = data.get('additional_entity_1') additional_entity_version_2 = data.get('additional_entity_2') allocation_entity_version = data.get('allocation_entity') requirement_entity_version = data.get('requirement_entity') new_learning_container = LearningContainer.objects.create( start_year=year) new_learning_unit = create_learning_unit(data, new_learning_container, year) while year < starting_academic_year.year + LEARNING_UNIT_CREATION_SPAN_YEARS: academic_year = mdl.academic_year.find_academic_year_by_year(year) create_learning_unit_structure( additional_entity_version_1, additional_entity_version_2, allocation_entity_version, data, new_learning_container, new_learning_unit, requirement_entity_version, status, academic_year) year += 1 return redirect('learning_units') else: return layout.render(request, "learning_unit/learning_unit_form.html", {'form': form})
def test_learning_unit_year_form(self): form = CreateLearningUnitYearForm(data=self.get_valid_data()) self.assertTrue(form.is_valid(), form.errors) url = reverse('learning_unit_year_add') response = self.client.post(url, data=self.get_base_form_data()) self.assertEqual(response.status_code, 302) count_learning_unit_year = LearningUnitYear.objects.all().count() self.assertEqual(count_learning_unit_year, 6)
def test_learning_unit_acronym_form(self): form = CreateLearningUnitYearForm(data=self.get_valid_data()) self.assertTrue(form.is_valid(), form.errors) form = CreateLearningUnitYearForm(data=self.get_empty_acronym()) self.assertFalse(form.is_valid(), form.errors) self.assertEqual(form.errors['acronym'], [_('This field is required.')]) form = CreateLearningUnitYearForm(data=self.get_faulty_acronym()) self.assertFalse(form.is_valid(), form.errors) self.assertEqual(form.errors['acronym'], [_('invalid_acronym')])
def learning_unit_create(request, academic_year): person = get_object_or_404(Person, user=request.user) form = CreateLearningUnitYearForm(person, initial={ 'academic_year': academic_year, 'subtype': FULL, "container_type": EMPTY_FIELD, 'language': language.find_by_code('FR') }) return layout.render(request, "learning_unit/learning_unit_form.html", {'form': form})
def test_create_learning_unit_year_requirement_entity_not_allowed(self): form = CreateLearningUnitYearForm( person=self.person, data=self.get_faulty_requirement_entity()) self.assertFalse(form.is_valid()) self.assertEqual(len(form.errors), 1) self.assertTrue('requirement_entity' in form.errors)