def get_friends(cls, user): try: user_key = user.key() except AttributeError: user_key = user entity = cls.all().filter("leader_id =", user_key.id()).get() entities = cls.all().filter("follower_ids =", user_key.id()).fetch(1000) ids = set(entity.follower_ids) | set([entity.leader_id for entity in entities]) return [TickUser.get_by_id(id) for id in ids]
def get_leaders(cls, follower): # TODO: make this work for more than 1000 leaders try: follower_key = follower.key() except AttributeError: follower_key = follower entities = cls.all().filter("follower_ids =", follower.id()).fetch(1000) return [TickUser.get_by_id(entity.leader_id) for entity in entities]
def get_followers(cls, leader): try: leader_key = leader.key() except AttributeError: leader_key = leader entity = cls.all().filter("leader_id =", leader_key.id()).get() if entity: return [TickUser.get_by_id(tickuser_id) for tickuser_id in entity.follower_ids] else: return []
def get_leaders(cls, follower): # TODO: make this work for more than 1000 leaders try: follower_key = follower.key() except AttributeError: follower_key = follower entities = cls.all().filter('follower_ids =', follower.id()).fetch(1000) return [TickUser.get_by_id(entity.leader_id) for entity in entities]
def get_friends(cls, user): try: user_key = user.key() except AttributeError: user_key = user entity = cls.all().filter('leader_id =', user_key.id()).get() entities = cls.all().filter('follower_ids =', user_key.id()).fetch(1000) ids = set(entity.follower_ids) | set( [entity.leader_id for entity in entities]) return [TickUser.get_by_id(id) for id in ids]
def get_followers(cls, leader): try: leader_key = leader.key() except AttributeError: leader_key = leader entity = cls.all().filter('leader_id =', leader_key.id()).get() if entity: return [ TickUser.get_by_id(tickuser_id) for tickuser_id in entity.follower_ids ] else: return []