def button_order_with_permission(context, title, id_button, value): permission_denied_message, disabled, root = _get_permission( context, is_eligible_to_change_education_group_content) if disabled: title = permission_denied_message else: education_group_year = context.get('education_group_year') person = context.get('person') if person.is_faculty_manager and education_group_year.type in GroupType.minor_major_list_choice( ): disabled, permission_denied_message = get_action_with_permission( context) if disabled: title = permission_denied_message if value == "up" and context["forloop"]["first"]: disabled = "disabled" if value == "down" and context["forloop"]["last"]: disabled = "disabled" return { 'title': title, 'id': id_button, 'value': value, 'disabled': disabled, 'icon': ICONS[value], }
def test_only_keep_block_when_parent_is_formation_and_child_is_minor_major_option_list_choice( self): expected_fields = ["block"] for name in GroupType.minor_major_option_list_choice(): with self.subTest(type=name): child_branch = GroupFactory(education_group_type__name=name) AuthorizedRelationshipFactory( parent_type=self.parent.education_group_type, child_type=child_branch.education_group_type) form = GroupElementYearForm(parent=self.parent, child_branch=child_branch) self.assertCountEqual(expected_fields, list(form.fields.keys()))
def create_initial_group_element_year_structure(parent_egys): children_created = defaultdict(list) if not parent_egys: return children_created first_parent = parent_egys[0] other_parents = parent_egys[1:] auth_rels = AuthorizedRelationship.objects.filter( parent_type=first_parent.education_group_type, min_count_authorized=1).annotate(rels_ordering=Case( *[ When(child_type__name=type_name, then=Value(i)) for i, type_name in enumerate(GroupType.ordered()) ], default=Value(len(GroupType.ordered())), output_field=IntegerField())).order_by("rels_ordering").only( 'child_type').select_related('child_type') for relationship in auth_rels: child_education_group_type = relationship.child_type validation_rule_title = _get_validation_rule( "title", child_education_group_type) validation_rule_partial_acronym = _get_validation_rule( "partial_acronym", child_education_group_type) grp_ele = _get_or_create_branch( child_education_group_type, validation_rule_title.initial_value if validation_rule_title else "", validation_rule_partial_acronym.initial_value if validation_rule_partial_acronym else "", first_parent) children_created[first_parent.id].append(grp_ele) for parent_egy in other_parents: grp_ele = _duplicate_branch(child_education_group_type, parent_egy, grp_ele.child_branch) children_created[parent_egy.id].append(grp_ele) return children_created
def test_disable_all_fields_except_block_when_parent_is_formation_and_child_is_minor_major_option_list_choice( self): expected_fields = ["block"] for name in GroupType.minor_major_option_list_choice(): with self.subTest(type=name): child_branch = GroupFactory(education_group_type__name=name) AuthorizedRelationshipFactory( parent_type=self.parent.education_group_type, child_type=child_branch.education_group_type) form = GroupElementYearForm(parent=self.parent, child_branch=child_branch) enabled_fields = [ name for name, field in form.fields.items() if not field.disabled ] self.assertCountEqual(expected_fields, enabled_fields)
def create_initial_group_element_year_structure(parent_egys): children_created = defaultdict(list) if not parent_egys: return children_created first_parent = parent_egys[0] other_parents = parent_egys[1:] auth_rels = AuthorizedRelationship.objects.filter( parent_type=first_parent.education_group_type, min_count_authorized=1 ).annotate( rels_ordering=Case( *[When(child_type__name=type_name, then=Value(i)) for i, type_name in enumerate(GroupType.ordered())], default=Value(len(GroupType.ordered())), output_field=IntegerField() ) ).order_by( "rels_ordering" ).only('child_type').select_related('child_type') for relationship in auth_rels: child_education_group_type = relationship.child_type validation_rule_title = _get_validation_rule("title", child_education_group_type) validation_rule_partial_acronym = _get_validation_rule("partial_acronym", child_education_group_type) grp_ele = _get_or_create_branch( child_education_group_type, validation_rule_title.initial_value if validation_rule_title else "", validation_rule_partial_acronym.initial_value if validation_rule_partial_acronym else "", first_parent ) children_created[first_parent.id].append(grp_ele) for parent_egy in other_parents: grp_ele = _duplicate_branch(child_education_group_type, parent_egy, grp_ele.child_branch) children_created[parent_egy.id].append(grp_ele) return children_created
def is_minor_major_option_list_choice(self): return self.type in GroupType.minor_major_option_list_choice()
def is_minor_major_option_list_choice(self): return self.education_group_type.name in GroupType.minor_major_option_list_choice( )
from base.models.learning_unit_year import LearningUnitYear from base.models.person import Person from base.models.prerequisite import Prerequisite from base.models.utils.utils import get_object_or_none from base.views.common import display_warning_messages NO_PREREQUISITES = [ TrainingType.MASTER_MA_120.name, TrainingType.MASTER_MD_120.name, TrainingType.MASTER_MS_120.name, TrainingType.MASTER_MA_180_240.name, TrainingType.MASTER_MD_180_240.name, TrainingType.MASTER_MS_180_240.name, MiniTrainingType.OPTION.name, MiniTrainingType.MOBILITY_PARTNERSHIP.name, ] + GroupType.get_names() @method_decorator(login_required, name='dispatch') class LearningUnitGenericDetailView(PermissionRequiredMixin, DetailView): model = LearningUnitYear context_object_name = "learning_unit_year" pk_url_kwarg = 'learning_unit_year_id' permission_required = 'base.can_access_education_group' raise_exception = True def get_person(self): return get_object_or_404(Person, user=self.request.user) def get_root(self):