Beispiel #1
0
 def test_ordered_by_name(self):
     EducationGroupTypeFactory(category=education_group_categories.TRAINING)
     expected_result = [
         self.complementary_module, self.options_list, self.subgroup
     ]
     self.assertEqual(expected_result,
                      list(find_authorized_types(category=self.category)))
Beispiel #2
0
 def test_when_no_authorized_type_matches(self):
     AuthorizedRelationshipFactory(parent_type=self.complementary_module,
                                   child_type=self.options_list)
     AuthorizedRelationshipFactory(parent_type=self.options_list,
                                   child_type=self.subgroup)
     educ_group_year = EducationGroupYearFactory(
         education_group_type=self.subgroup)
     result = find_authorized_types(parents=[educ_group_year])
     self.assertEqual(result.count(), 0)
Beispiel #3
0
    def __init__(self, parent, category, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields["name"].queryset = find_authorized_types(category=category,
                                                             parents=parent)

        self.fields["name"].label = _(
            "Which type of %(category)s do you want to create ?") % {
                "category": _(category)
            }
Beispiel #4
0
 def test_filter_on_authorized_types(self):
     doctorate = EducationGroupTypeFactory(name='PhD', category=education_group_categories.TRAINING)
     AuthorizedRelationshipFactory(parent_type=doctorate, child_type=self.options_list)
     educ_group_year = EducationGroupYearFactory(education_group_type=doctorate)
     result = find_authorized_types(parents=[educ_group_year])
     self.assertEqual(len(result), 1)
     self.assertIn(self.options_list, result)
     self.assertNotIn(self.subgroup, result)
     self.assertNotIn(self.complementary_module, result)
Beispiel #5
0
    def __init__(self, parent, category, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.parent = parent
        self.fields["name"].queryset = find_authorized_types(
            category=category,
            parents=self.parent
        )

        self.fields["name"].label = _("Which type of %(category)s do you want to create ?") % {
            "category": Categories[category].value
        }
Beispiel #6
0
    def __init__(self, parent, category, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.parent = parent
        self.fields["name"].queryset = find_authorized_types(
            category=category, parents=self.parent).exclude(
                name__in=DISABLED_OFFER_TYPE
            )  # Temporary exclude Major and Mobility partnership (OSIS-2911)

        self.fields["name"].label = _(
            "Which type of %(category)s do you want to create ?") % {
                "category": Categories[category].value
            }
Beispiel #7
0
    def _filter_education_group_type(self):
        # In case of update, we need to fetch all parents
        if self.instance.pk:
            parents = EducationGroupYear.objects.filter(
                groupelementyear__child_branch=self.instance.pk)
        elif self.parent:
            parents = [self.parent]

        else:
            parents = []

        queryset = education_group_type.find_authorized_types(
            category=self.category, parents=parents)
        self.fields["education_group_type"].queryset = queryset
Beispiel #8
0
    def __init__(self, *args, education_group_type=None, user=None, **kwargs):
        self.user = user
        self.parent = kwargs.pop("parent", None)

        if not education_group_type and not kwargs.get('instance'):
            raise ImproperlyConfigured("Provide an education_group_type or an instance")

        self.education_group_type = education_group_type
        if self.education_group_type:
            if education_group_type not in find_authorized_types(self.category, self.parent):
                raise PermissionDenied("Unauthorized type {} for {}".format(education_group_type, self.category))

        super().__init__(*args, **kwargs)
        self._set_initial_values()
        self._filter_education_group_type()
        self._filter_management_entity_according_to_person()
        self._init_and_disable_academic_year()
        self._preselect_entity_version_from_entity_value()
Beispiel #9
0
def check_authorized_type(education_group,
                          category=None,
                          raise_exception=False):
    if not education_group:
        return True

    result = find_authorized_types(category=category,
                                   parents=[education_group]).exists()

    can_raise_exception(
        raise_exception, result,
        _("No type of education group can be created as child of %(category)s of type %(type)s"
          ) % {
              "category": _(education_group.education_group_type.category),
              "type": education_group.education_group_type.name,
          })

    return result
Beispiel #10
0
    def __init__(self, *args, education_group_type=None, **kwargs):
        self.parent = kwargs.pop("parent", None)

        if not education_group_type and not kwargs.get('instance'):
            raise ImproperlyConfigured(
                "Provide an education_group_type or an instance")

        self.education_group_type = education_group_type
        if self.education_group_type:
            if education_group_type not in find_authorized_types(
                    self.category, self.parent):
                raise PermissionDenied("Unauthorized type {} for {}".format(
                    education_group_type, self.category))

        super().__init__(*args, **kwargs)
        self._set_initial_values()
        self._filter_education_group_type()
        self._init_and_disable_academic_year()
        self._preselect_entity_version_from_entity_value()
Beispiel #11
0
def check_authorized_type(education_group, category, raise_exception=False):
    if not education_group or not category:
        return True

    result = find_authorized_types(category=category,
                                   parents=[education_group]).exists()

    parent_category = education_group.education_group_type.category
    can_raise_exception(
        raise_exception, result,
        pgettext(
            "female"
            if parent_category in [TRAINING, MINI_TRAINING] else "male",
            "No type of %(child_category)s can be created as child of %(category)s of type %(type)s"
        ) % {
            "child_category": _(category),
            "category": _(education_group.education_group_type.category),
            "type": education_group.education_group_type.name,
        })

    return result
Beispiel #12
0
def check_authorized_type(education_group, category, raise_exception=False):
    if not education_group or not category:
        return True

    result = find_authorized_types(
        category=category.name,
        parents=[education_group]
    ).exists()

    parent_category = education_group.education_group_type.category
    can_raise_exception(
        raise_exception, result,
        pgettext(
            "female" if parent_category in [TRAINING, MINI_TRAINING] else "male",
            "No type of %(child_category)s can be created as child of %(category)s of type %(type)s"
        ) % {
            "child_category": category.value,
            "category": education_group.education_group_type.get_category_display(),
            "type": education_group.education_group_type.get_name_display(),
        })

    return result