コード例 #1
0
ファイル: models.py プロジェクト: twidi/django-flag
 def __unicode__(self):
     """
     Show the flagged object in the unicode string
     """
     app_label, model = get_content_type_tuple(
             self.flagged_content.content_type_id)
     return u'flag on %s.%s #%s by user #%s' % (
             app_label, model, self.flagged_content.object_id, self.user_id)
コード例 #2
0
 def __unicode__(self):
     """
     Show the flagged object in the unicode string
     """
     app_label, model = get_content_type_tuple(
         self.flagged_content.content_object)
     return u'flag on %s.%s #%s by user #%s' % (
         app_label, model, self.flagged_content.object_id, self.user_id)
コード例 #3
0
ファイル: models.py プロジェクト: liberation/django-flag
 def filter_for_model(self, model, only_object_ids=False):
     """
     Return a queryset to filter FlaggedContent on a given model
     If `only_object_ids` is True, the queryset will only returns a list of
     object ids of the `model` model. It's usefull if the flagged model can
     not have a GenericRelation (if you can't touch the model,
     like auth.User) :
         User.objects.filter(id__in=FlaggedContent.objects.filter_for_model(
             User, True).filter(status=2))
     """
     app_label, model = get_content_type_tuple(model)
     queryset = self.filter(content_type__app_label=app_label, content_type__model=model)
     if only_object_ids:
         queryset = queryset.values_list("object_id", flat=True)
     return queryset
コード例 #4
0
 def filter_for_model(self, model, only_object_ids=False):
     """
     Return a queryset to filter FlaggedContent on a given model
     If `only_object_ids` is True, the queryset will only returns a list of
     object ids of the `model` model. It's usefull if the flagged model can
     not have a GenericRelation (if you can't touch the model,
     like auth.User) :
         User.objects.filter(id__in=FlaggedContent.objects.filter_for_model(
             User, True).filter(status=2))
     """
     app_label, model = get_content_type_tuple(model)
     queryset = self.filter(content_type__app_label=app_label,
                            content_type__model=model)
     if only_object_ids:
         queryset = queryset.values_list('object_id', flat=True)
     return queryset
コード例 #5
0
    def test_flag_settings(self):
        """
        Test settings
        """
        model = ModelWithAuthor
        model_name = 'tests.modelwithauthor'
        self.assertEqual('.'.join(get_content_type_tuple(model)), model_name)

        # no settings for this model
        flag_settings.MODELS_SETTINGS = {}
        flag_settings.SEND_MAILS = True
        self.assertEqual(flag_settings.SEND_MAILS,
                flag_settings.get_for_model(model_name, 'SEND_MAILS'))
        self.assertEqual(flag_settings.SEND_MAILS,
                flag_settings.get_for_model(model, 'SEND_MAILS'))

        # a setting for this model
        flag_settings.MODELS_SETTINGS[model_name] = {}
        flag_settings.MODELS_SETTINGS[model_name]['SEND_MAILS'] = False
        self.assertNotEqual(flag_settings.SEND_MAILS,
                            flag_settings.get_for_model(model_name,
                                                        'SEND_MAILS'))
        self.assertNotEqual(flag_settings.SEND_MAILS,
                            flag_settings.get_for_model(model, 'SEND_MAILS'))

        # bad model
        self.assertEqual(flag_settings.SEND_MAILS,
                flag_settings.get_for_model('bad-model', 'SEND_MAILS'))

        # forbidden setting
        flag_settings.MODELS = (model_name,)
        flag_settings.MODELS_SETTINGS = {}
        self.assertEqual(flag_settings.MODELS,
                         flag_settings.get_for_model(model_name, 'MODELS'))
        flag_settings.MODELS_SETTINGS[model_name] = {}
        flag_settings.MODELS_SETTINGS[model_name]['MODELS'] = (
                'tests.modelwithoutauthor',)
        self.assertEqual(flag_settings.MODELS,
                         flag_settings.get_for_model(model_name, 'MODELS'))

        # inexistint setting
        self.assertRaises(AttributeError,
                          flag_settings.get_for_model,
                          model_name,
                          'INEXISTING_SETTINGS')
コード例 #6
0
def get_for_model(model, name):
    """
    Try to get the `name` settings for a specific model.
    See `utils.get_content_type_tuple` for description of the `name` parameter
    The fallback in all case (all exceptions or simply no specific
    settings) is the basic settings
    """
    from flag import settings as flag_settings
    result = getattr(flag_settings, name)
    if name not in _ONLY_GLOBAL_SETTINGS:
        try:
            model_id = '%s.%s' % get_content_type_tuple(model)
        except:
            pass
        else:
            if name in MODELS_SETTINGS.get(model_id, {}):
                result = MODELS_SETTINGS[model_id][name]
    return result
コード例 #7
0
ファイル: settings.py プロジェクト: lauxley/django-flag
def get_for_model(model, name):
    """
    Try to get the `name` settings for a specific model.
    See `utils.get_content_type_tuple` for description of the `name` parameter
    The fallback in all case (all exceptions or simply no specific
    settings) is the basic settings
    """
    from flag import settings as flag_settings
    result = getattr(flag_settings, name)
    if name not in _ONLY_GLOBAL_SETTINGS:
        try:
            model_id = '%s.%s' % get_content_type_tuple(model)
        except:
            pass
        else:
            if name in MODELS_SETTINGS.get(model_id, {}):
                result = MODELS_SETTINGS[model_id][name]
    return result
コード例 #8
0
ファイル: models.py プロジェクト: twidi/django-flag
    def model_can_be_flagged(self, content_type):
        """
        Return True if the model is listed in the MODELS settings (or if this
        settings is not defined)
        See `utils.get_content_type_tuple` for description of the
        `content_Type` parameter
        """
        if flag_settings.MODELS is None:
            return True

        # try to find app and model from the content_type
        try:
            app_label, model = get_content_type_tuple(content_type)
        except:
            return False

        # finally we can check
        model = '%s.%s' % (app_label, model)
        return model in flag_settings.MODELS
コード例 #9
0
    def model_can_be_flagged(self, content_type):
        """
        Return True if the model is listed in the MODELS settings (or if this
        settings is not defined)
        See `utils.get_content_type_tuple` for description of the
        `content_Type` parameter
        """
        if flag_settings.MODELS is None:
            return True

        # try to find app and model from the content_type
        try:
            app_label, model = get_content_type_tuple(content_type)
        except:
            return False

        # finally we can check
        model = '%s.%s' % (app_label, model)
        return model in flag_settings.MODELS
コード例 #10
0
ファイル: models.py プロジェクト: liberation/django-flag
 def __unicode__(self):
     """
     Show the flagged object in the unicode string
     """
     app_label, model = get_content_type_tuple(self.content_type_id)
     return u"%s.%s #%s" % (app_label, model, self.object_id)
コード例 #11
0
 def __unicode__(self):
     """
     Show the flagged object in the unicode string
     """
     app_label, model = get_content_type_tuple(self.content_type_id)
     return u'%s.%s #%s' % (app_label, model, self.object_id)