Exemple #1
0
 def test_external_learning_unit_form_is_valid(self):
     data = get_valid_external_learning_unit_form_data(
         self.academic_year, self.person)
     form = ExternalLearningUnitBaseForm(person=self.person,
                                         academic_year=self.academic_year,
                                         data=data)
     self.assertTrue(form.is_valid(), form.errors)
 def _get_learning_unit_base_form(self,
                                  ac_year,
                                  learning_unit_instance=None,
                                  data=None,
                                  start_year=None):
     form_kwargs = {
         'person':
         self.person,
         'learning_unit_instance':
         learning_unit_instance,
         'academic_year':
         ac_year,
         'start_year':
         start_year,
         'data':
         data.copy() if data else None,
         'learning_unit_full_instance':
         self.learning_unit_full_instance,
         'postposal':
         not data,
         'start_anac':
         self.start_postponement
         if self.subtype == learning_unit_year_subtypes.PARTIM else None
     }
     if self.external:
         return ExternalLearningUnitBaseForm(
             **form_kwargs
         ) if self.subtype == learning_unit_year_subtypes.FULL else ExternalPartimForm(
             **form_kwargs)
     return FullForm(**form_kwargs) if self.subtype == learning_unit_year_subtypes.FULL else \
         PartimForm(**form_kwargs)
Exemple #3
0
    def test_external_learning_unit_form_init(self):
        form = ExternalLearningUnitBaseForm(person=self.person, academic_year=self.academic_year)

        context = form.get_context()
        self.assertEqual(context['subtype'], FULL)
        self.assertIsInstance(context['learning_unit_form'], LearningUnitModelForm)
        self.assertIsInstance(context['learning_unit_year_form'], LearningUnitYearModelForm)
        self.assertIsInstance(context['learning_container_year_form'], LearningContainerYearExternalModelForm)
        self.assertIsInstance(context['learning_unit_external_form'], CograduationExternalLearningUnitModelForm)
Exemple #4
0
    def test_external_learning_unit_form_save(self):
        data = get_valid_external_learning_unit_form_data(self.academic_year, self.person)
        form = ExternalLearningUnitBaseForm(person=self.person, academic_year=self.academic_year, data=data,
                                            start_year=self.academic_year.year)
        self.assertTrue(form.is_valid(), form.errors)
        luy = form.save()

        self.assertIsInstance(luy, LearningUnitYear)
        self.assertEqual(luy.learning_container_year.container_type, EXTERNAL)
        self.assertEqual(luy.acronym[0], 'E')
        self.assertEqual(luy.externallearningunityear.author, self.person)
        self.assertEqual(luy.learning_unit.start_year, self.academic_year.year)
Exemple #5
0
def get_external_learning_unit_creation_form(request, academic_year):
    person = get_object_or_404(Person, user=request.user)
    academic_year = get_object_or_404(AcademicYear, pk=academic_year)

    external_form = ExternalLearningUnitBaseForm(person, academic_year,
                                                 request.POST or None)

    if external_form.is_valid():
        learning_unit_year = external_form.save()
        show_success_learning_unit_year_creation_message(
            request, learning_unit_year, 'learning_unit_successfuly_created')
        return redirect('learning_unit',
                        learning_unit_year_id=learning_unit_year.pk)

    return layout.render(request,
                         "learning_unit/simple/creation_external.html",
                         external_form.get_context())