Ejemplo n.º 1
0
    def test_post_with_errors(self):
        expected_educ_group_year, wrong_post_data = _get_valid_post_data(self.category)
        wrong_post_data['management_entity'] = None
        wrong_post_data['end_year'] = "some text"
        wrong_post_data["max_constraint"] = expected_educ_group_year.min_constraint - 1

        form = MiniTrainingForm(wrong_post_data, education_group_type=self.egt, user=UserFactory())
        self.assertFalse(form.is_valid(), form.errors)
        self.assertEqual(len(form.errors), 3, form.errors)
Ejemplo n.º 2
0
def _update_mini_training(request, education_group_year, root):
    # TODO :: IMPORTANT :: Fix urls patterns to get the GroupElementYear_id and the root_id in the url path !
    # TODO :: IMPORTANT :: Need to upodate form to filter on list of parents, not only on the first direct parent
    form = MiniTrainingForm(request.POST or None,
                            instance=education_group_year)

    if form.is_valid():
        return _common_success_redirect(request, form.save(), root)

    return layout.render(
        request, "education_group/update_minitrainings.html", {
            "form_education_group_year": form.forms[forms.ModelForm],
            "education_group_year": education_group_year,
            "form_education_group": form.forms[EducationGroupModelForm]
        })
Ejemplo n.º 3
0
 def test_when_both_of_two_forms_are_valid(self, mock_is_valid,
                                           mock_post_clean,
                                           mock_mintraining_is_valid):
     self.assertTrue(
         MiniTrainingForm(self.post_data,
                          user=self.user,
                          education_group_type=self.egt).is_valid())
Ejemplo n.º 4
0
 def test_when_education_group_model_form_is_not_valid(self, mock_is_valid):
     self.assertFalse(
         MiniTrainingForm(
             self.post_data,
             user=UserFactory(),
             education_group_type=self.egt
         ).is_valid()
     )
Ejemplo n.º 5
0
def _update_mini_training(request, education_group_year, root,
                          groupelementyear_formset):
    # TODO :: IMPORTANT :: Fix urls patterns to get the GroupElementYear_id and the root_id in the url path !
    # TODO :: IMPORTANT :: Need to upodate form to filter on list of parents, not only on the first direct parent
    form = MiniTrainingForm(request.POST or None,
                            instance=education_group_year,
                            user=request.user)

    if request.method == 'POST':
        if form.is_valid() and groupelementyear_formset.is_valid():
            return _common_success_redirect(request, form, root,
                                            groupelementyear_formset)
        else:
            show_error_message_for_form_invalid(request)

    return render(
        request, "education_group/update_minitrainings.html", {
            "form_education_group_year": form.forms[forms.ModelForm],
            "education_group_year": education_group_year,
            "form_education_group": form.forms[EducationGroupModelForm],
            'group_element_years': groupelementyear_formset
        })
Ejemplo n.º 6
0
def create_education_group(request, category=None, parent_id=None):
    parent = get_object_or_404(EducationGroupYear,
                               id=parent_id) if parent_id is not None else None

    forms_by_category = {
        education_group_categories.GROUP:
        GroupForm(request.POST or None, parent=parent),
        education_group_categories.TRAINING:
        TrainingForm(request.POST or None, parent=parent),
        education_group_categories.MINI_TRAINING:
        MiniTrainingForm(request.POST or None, parent=parent),
    }

    form_education_group_year = forms_by_category.get(category)

    if form_education_group_year.is_valid():
        education_group_year = form_education_group_year.save()

        parent_id = parent.pk if parent else education_group_year.pk

        success_msg = create_success_message_for_creation_education_group_year(
            parent_id, education_group_year)
        display_success_messages(request, success_msg, extra_tags='safe')

        url = reverse("education_group_read",
                      args=[parent_id, education_group_year.pk])

        return redirect(url)

    templates_by_category = {
        education_group_categories.GROUP:
        "education_group/create_groups.html",
        education_group_categories.TRAINING:
        "education_group/create_trainings.html",
        education_group_categories.MINI_TRAINING:
        "education_group/create_mini_trainings.html",
    }

    return layout.render(
        request, templates_by_category.get(category), {
            "form_education_group_year":
            form_education_group_year.forms[forms.ModelForm],
            "form_education_group":
            form_education_group_year.forms[EducationGroupModelForm],
            "parent":
            parent
        })