Пример #1
0
 def test(self) :
     class A() :
         def __init__(self,id) :
             self.id = id
     a = A(123)
     from django.conf import settings
     self.assertEquals(cache_key('FROM_OBJ',obj=a), settings.DOMAIN_NAME + ":FROM_OBJ:A:123")
     self.assertEquals(cache_key('FROM_CLASS_AND_ID',cls=A,id=456), settings.DOMAIN_NAME + ":FROM_CLASS_AND_ID:A:456")
Пример #2
0
def get_enclosure_set(self, seen=None):
    key = cache_key(MULTI_LEVEL_MEMBERSHIP_KEY, self)
    if redis.exists(key):
        return TgGroup.objects.filter(id__in=redis.smembers(key))

    es = get_enclosure_id_set(self.__class__, self.id)
    add_to_cached_set(key, es)

    return TgGroup.objects.filter(id__in=[x for x in es])
Пример #3
0
def get_enclosure_set(self, seen=None):
    key = cache_key(MULTI_LEVEL_MEMBERSHIP_KEY, self)
    if redis.exists(key) :
        return TgGroup.objects.filter(id__in=redis.smembers(key))

    es = get_enclosure_id_set(self.__class__, self.id)
    add_to_cached_set(key, es)

    return TgGroup.objects.filter(id__in=[x for x in es])
Пример #4
0
def get_enclosure_ids(cls, id):
    """ Note, these are depth 1 membership ids. And note also that all enclosures, are, by definition TgGroup
    cls is the actual python class (django model class) ... cache_key takes its name
    """
    key = cache_key(ONE_LEVEL_MEMBERSHIP_KEY, cls=cls, id=id)
    if redis.exists(key):
        return redis.smembers(key)

    # if not cached, get the object and get its enclosures
    obj = cls.objects.get(id=id)
    memberships = set([x.id for x in obj.get_enclosures()])

    add_to_cached_set(key, memberships)
    return memberships
Пример #5
0
def get_enclosure_ids(cls,id) :
    """ Note, these are depth 1 membership ids. And note also that all enclosures, are, by definition TgGroup
    cls is the actual python class (django model class) ... cache_key takes its name
    """
    key = cache_key(ONE_LEVEL_MEMBERSHIP_KEY, cls=cls, id=id)
    if redis.exists(key) :
        return redis.smembers(key)

    # if not cached, get the object and get its enclosures
    obj = cls.objects.get(id=id)
    memberships = set([x.id for x in obj.get_enclosures()])
    
    add_to_cached_set(key, memberships)
    return memberships
Пример #6
0
def get_enclosures(self, levels=None) :
    # XXX TO-DO given that this is now different for Users and Groups 
    # no need to have one function assigned to both with a different test
    # just put different versions into respective classes
    """Give us all the things of which this user/group is a member_of
    """

    key = cache_key(ONE_LEVEL_MEMBERSHIP_KEY, self)
    if redis.exists(key) :
        return TgGroup.objects.filter(id__in=get_enclosure_ids(self.__class__, self.id))
 
    if levels == None:
        levels = ['member', 'host', 'public']

    if isinstance(self, User):
        return self.groups.filter(level__in=levels)
    elif isinstance(self, TgGroup):
        return self.parent_groups.filter(level__in=levels)
Пример #7
0
def get_enclosures(self, levels=None):
    # XXX TO-DO given that this is now different for Users and Groups
    # no need to have one function assigned to both with a different test
    # just put different versions into respective classes
    """Give us all the things of which this user/group is a member_of
    """

    key = cache_key(ONE_LEVEL_MEMBERSHIP_KEY, self)
    if redis.exists(key):
        return TgGroup.objects.filter(
            id__in=get_enclosure_ids(self.__class__, self.id))

    if levels == None:
        levels = ['member', 'host', 'public']

    if isinstance(self, User):
        return self.groups.filter(level__in=levels)
    elif isinstance(self, TgGroup):
        return self.parent_groups.filter(level__in=levels)
Пример #8
0
def get_enclosure_id_set(cls, self_id, seen=None):

    key = cache_key(MULTI_LEVEL_MEMBERSHIP_KEY, cls=cls, id=self_id)
    if redis.exists(key):
        return redis.smembers(key)

    if not seen:
        seen = set([self_id])

    if cls == TgGroup:
        es = set([self_id])
    else:
        es = set([])
    for e_id in get_enclosure_ids(cls, self_id):
        if e_id not in seen:
            seen.add(e_id)
            multi_memberships = get_enclosure_id_set(TgGroup, e_id, seen)
            es = es.union(set(multi_memberships))
            seen = seen.union([m for m in multi_memberships])

    add_to_cached_set(key, es)
    return es
Пример #9
0
def get_enclosure_id_set(cls, self_id, seen=None) :

    key = cache_key(MULTI_LEVEL_MEMBERSHIP_KEY,cls=cls, id=self_id)
    if redis.exists(key) :
        return redis.smembers(key)

    if not seen :
        seen = set([self_id])

    if cls == TgGroup :
        es = set([self_id])
    else :
        es = set([])
    for e_id in get_enclosure_ids(cls, self_id ) :
        if e_id not in seen :
            seen.add(e_id)
            multi_memberships = get_enclosure_id_set(TgGroup, e_id, seen)
            es = es.union(set(multi_memberships))
            seen = seen.union([m for m in multi_memberships])

    add_to_cached_set(key, es)
    return es