def _update_group(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 update form to filter on list of parents, not only on the first direct parent form_education_group_year = GroupForm(request.POST or None, instance=education_group_year, user=request.user) html_page = "education_group/update_groups.html" has_content = len(groupelementyear_formset.queryset) > 0 if request.method == 'POST': if form_education_group_year.is_valid() and ( not has_content or groupelementyear_formset.is_valid()): return _common_success_redirect( request, form_education_group_year, root, groupelementyear_formset if has_content else None) else: show_error_message_for_form_invalid(request) return render( request, html_page, { "education_group_year": education_group_year, "form_education_group_year": form_education_group_year.forms[forms.ModelForm], "form_education_group": form_education_group_year.forms[EducationGroupModelForm], 'group_element_years': groupelementyear_formset, 'show_minor_major_option_table': education_group_year.is_minor_major_option_list_choice })
def test_create_with_parent(self, mock_find_authorized_types): parent = GroupFactory() form = GroupForm(data=self.post_data, parent=parent, user=self.user, education_group_type=self.egt) self.assertTrue(form.is_valid(), form.errors) education_group_year = form.save() self.assertTrue(GroupElementYear.objects.get(child_branch=education_group_year, parent=parent))
def test_create(self): form = GroupForm(data=self.post_data, parent=None) self.assertTrue(form.is_valid(), form.errors) education_group_year = form.save() self.assertEqual(education_group_year.education_group.start_year, self.expected_educ_group_year.academic_year.year) self.assertIsNone(education_group_year.education_group.end_year)
def _update_group(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 update form to filter on list of parents, not only on the first direct parent form_education_group_year = GroupForm(request.POST or None, instance=education_group_year) html_page = "education_group/update_groups.html" if form_education_group_year.is_valid(): return _common_success_redirect(request, form_education_group_year.save(), root) return layout.render( request, html_page, { "education_group_year": education_group_year, "form_education_group_year": form_education_group_year.forms[forms.ModelForm], })