Esempio n. 1
0
    def test_from_string(self):
        cl = get_model_class_from_string('auth.User')
        assert cl is User

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('some')

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('etc.InheritedModel')
Esempio n. 2
0
    def test_from_string(self):
        cl = get_model_class_from_string('auth.User')
        assert cl is User

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('some')

        with pytest.raises(ImproperlyConfigured):
            get_model_class_from_string('etc.InheritedModel')
Esempio n. 3
0
    def get_flags_for_objects(cls, objects_list, user=None, status=None):
        """Returns a dictionary with flag objects associated with the given model objects.
        The dictionary is indexed by objects IDs.
        Each dict entry contains a list of associated flag objects.

        :param list, QuerySet objects_list:
        :param User user:
        :param int status:
        :rtype: dict
        """
        return get_model_class_from_string(MODEL_FLAG).get_flags_for_objects(objects_list, user=user, status=status)
Esempio n. 4
0
    def get_flags_for_types(cls, mdl_classes, user=None, status=None, allow_empty=True):
        """Returns a dictionary with flag objects associated with the given model classes (types).
        The dictionary is indexed by model classes.
        Each dict entry contains a list of associated flag objects.

        :param list mdl_classes:
        :param User user:
        :param int status:
        :param bool allow_empty: Flag. Include results for all given types, even those without associated flags.
        :rtype: dict
        """
        return get_model_class_from_string(MODEL_FLAG).get_flags_for_types(
            mdl_classes, user=user, status=status, allow_empty=allow_empty)
Esempio n. 5
0
def get_tie_model():
    """Returns the Tie model, set for the project."""
    return get_model_class_from_string(MODEL_TIE)
Esempio n. 6
0
def get_category_model():
    """Returns the Category model, set for the project."""
    return get_model_class_from_string(MODEL_CATEGORY)
Esempio n. 7
0
 def hit_count(self):
     ctype = ContentType.objects.get_for_model(self.__class__)
     hit_count, created = get_model_class_from_string(
         MODEL_HITCOUNT).objects.get_or_create(content_type=ctype,
                                               object_pk=self.pk)
     return hit_count
Esempio n. 8
0
def get_tie_model() -> Type['TieBase']:
    """Returns the Tie model, set for the project."""
    return get_model_class_from_string(MODEL_TIE)
Esempio n. 9
0
def get_category_model() -> Type['CategoryBase']:
    """Returns the Category model, set for the project."""
    return get_model_class_from_string(MODEL_CATEGORY)