コード例 #1
0
def roles_key(user, obj):
    if obj.__class__ in (User, AnonymousUser,):
        obj_id = get_user_pk(obj)
    else:
        obj_id = obj.pk
    obj_type = str(obj.__class__.__name__).lower()
    obj_counter = get_counter(obj)
    user_id = get_user_pk(user)
    user_counter = get_counter(user)
    return "%s-%s-%s-%s-%s" % (user_id, user_counter, obj_type, obj_id,
                               obj_counter)
コード例 #2
0
def counter_key(obj):
    if obj.__class__ in (User, AnonymousUser,):
        pk = get_user_pk(obj)
    else:
        pk = obj.pk
    obj_type = str(obj.__class__.__name__).lower()
    return "%s-%s" % (obj_type, pk)
コード例 #3
0
ファイル: models.py プロジェクト: chrisglass/django-rulez
 def get_roles(self, user):
     """
     Gets all roles this user has for this object and caches it on the
     instance.
     Without the instance cache every call to has_role() would hit the
     cache backend.
     """
     rolez = getattr(self, '_rolez', {})
     pk = get_user_pk(user)
     if not pk in rolez.keys():
         rolez[pk] = get_roles(user, self)
     self._rolez = rolez
     return self._rolez[pk]
コード例 #4
0
 def get_roles(self, user):
     """
     Gets all roles this user has for this object and caches it on the
     instance.
     Without the instance cache every call to has_role() would hit the
     cache backend.
     """
     rolez = getattr(self, '_rolez', {})
     pk = get_user_pk(user)
     if not pk in rolez.keys():
         rolez[pk] = get_roles(user, self)
     self._rolez = rolez
     return self._rolez[pk]
コード例 #5
0
 def test_get_anonymous_user_works(self):
     anon = AnonymousUser()
     res = get_user_pk(anon)
     self.assertEqual(res, 'anonymous')
コード例 #6
0
 def test_get_anonymous_user_works(self):
     anon = AnonymousUser()
     res = get_user_pk(anon)
     self.assertEqual(res, 'anonymous')