def _update_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 update form to filter on list of parents, not only on the first direct parent form_education_group_year = TrainingForm(request.POST or None, user=request.user, instance=education_group_year) coorganization_formset = None forms_valid = all([ form_education_group_year.is_valid(), groupelementyear_formset.is_valid() ]) if has_coorganization(education_group_year): coorganization_formset = OrganizationFormset( data=request.POST or None, form_kwargs={ 'education_group_year': education_group_year, 'user': request.user }, queryset=education_group_year.coorganizations) forms_valid = forms_valid and coorganization_formset.is_valid() if request.method == 'POST': if forms_valid: if has_coorganization(education_group_year): coorganization_formset.save() return _common_success_redirect(request, form_education_group_year, root, groupelementyear_formset) else: show_error_message_for_form_invalid(request) return render( request, "education_group/update_trainings.html", { "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], "form_coorganization": coorganization_formset, "form_hops": form_education_group_year.hops_form, "show_coorganization": has_coorganization(education_group_year), "show_diploma_tab": form_education_group_year.show_diploma_tab(), 'can_change_coorganization': perms.is_eligible_to_change_coorganization( person=request.user.person, education_group=education_group_year, ), 'group_element_years': groupelementyear_formset, "is_finality_types": education_group_year.is_finality })
def _update_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 update form to filter on list of parents, not only on the first direct parent form_education_group_year = TrainingForm(request.POST or None, user=request.user, instance=education_group_year) coorganization_formset = None if show_coorganization(education_group_year): coorganization_formset = OrganizationFormset( data=request.POST or None, form_kwargs={ 'education_group_year': education_group_year, 'user': request.user }, queryset=education_group_year.coorganizations) if form_education_group_year.is_valid( ) and coorganization_formset.is_valid(): coorganization_formset.save() return _common_success_redirect(request, form_education_group_year, root) else: if form_education_group_year.is_valid(): return _common_success_redirect(request, form_education_group_year, root) return render( request, "education_group/update_trainings.html", { "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], "form_coorganization": coorganization_formset, "form_hops": form_education_group_year.hops_form, "show_coorganization": show_coorganization(education_group_year), 'can_change_coorganization': perms.is_eligible_to_change_coorganization( person=request.user.person, education_group=education_group_year, ) })
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # This objects are mandatory for all education group views context['person'] = self.person # FIXME same param context['root'] = self.root context['root_id'] = self.root.pk context['parent'] = self.root context['parent_training'] = self.object.parent_by_training() if self.with_tree: context['tree'] = json.dumps( EducationGroupHierarchy(self.root).to_json()) context['group_to_parent'] = self.request.GET.get( "group_to_parent") or '0' context[ 'can_change_education_group'] = perms.is_eligible_to_change_education_group( person=self.person, education_group=context['object'], ) context[ 'can_change_coorganization'] = perms.is_eligible_to_change_coorganization( person=self.person, education_group=context['object'], ) context['enums'] = mdl.enums.education_group_categories context['current_academic_year'] = self.current_academic_year context["show_identification"] = self.show_identification() context["show_diploma"] = self.show_diploma() context["show_general_information"] = self.show_general_information() context[ "show_skills_and_achievements"] = self.show_skills_and_achievements( ) context["show_administrative"] = self.show_administrative() context["show_content"] = self.show_content() context["show_utilization"] = self.show_utilization() context["show_admission_conditions"] = self.show_admission_conditions() return context
def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) # This objects are mandatory for all education group views context['person'] = self.person # FIXME same param context['root'] = self.root context['root_id'] = self.root.pk context['parent'] = self.root context['parent_training'] = self.object.parent_by_training() context["show_identification"] = self.show_identification() context["show_diploma"] = self.show_diploma() context["show_general_information"] = self.show_general_information() context["show_skills_and_achievements"] = self.show_skills_and_achievements() context["show_administrative"] = self.show_administrative() context["show_content"] = self.show_content() context["show_utilization"] = self.show_utilization() context["show_admission_conditions"] = self.show_admission_conditions() if self.with_tree: # FIXME: resolve dependency in other way from program_management.business.group_element_years.group_element_year_tree import EducationGroupHierarchy education_group_hierarchy_tree = EducationGroupHierarchy(self.root, tab_to_show=self.request.GET.get('tab_to_show')) context['tree'] = json.dumps(education_group_hierarchy_tree.to_json()) context['group_to_parent'] = self.request.GET.get("group_to_parent") or '0' context['can_change_education_group'] = perms.is_eligible_to_change_education_group( person=self.person, education_group=context['object'], ) context['can_change_coorganization'] = perms.is_eligible_to_change_coorganization( person=self.person, education_group=context['object'], ) context['enums'] = mdl.enums.education_group_categories context['current_academic_year'] = self.starting_academic_year context['selected_element_clipboard'] = self.get_selected_element_for_clipboard() context['form_xls_custom'] = CustomXlsForm() return context