コード例 #1
0
    def get_followers(self, userid=None, username=None, page=1, query_id=None):
        """Obtiene la lista de followers de un usuario
            
            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param username: nombre del usuario (user.username)
            :type username: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
            
            :raises: AttributeError
        """

        if username is not None:
            userkey = self.get_by_username(username, keys_only=True)
        elif userid is not None:
            userkey = db.Key.from_path(User.kind(), userid)
        else:
            raise AttributeError()
        from georemindme.paging import PagedQuery
        from models_acc import UserFollowingIndex

        followers = UserFollowingIndex.all().filter("following =", userkey).order("-created")
        p = PagedQuery(followers, id=query_id)
        from georemindme.funcs import fetch_parents

        users = fetch_parents(p.fetch_page(page))
        return [
            p.id,
            [
                {
                    "id": u.id,
                    "username": u.username,
                    "is_following": u.has_follower(userkey=userkey),
                    "profile": u.profile,
                }
                for u in users
            ],
        ]
コード例 #2
0
ファイル: helpers.py プロジェクト: shafiabdul/GeoRemindMe_Web
    def get_followers(self, userid=None, username=None, page=1, query_id=None):
        """Obtiene la lista de followers de un usuario
            
            :param userid: id del usuario (user.id)
            :type userid: :class:`string`
            :param username: nombre del usuario (user.username)
            :type username: :class:`string`
            :param page: numero de pagina a mostrar
            :type param: int
            :param query_id: identificador de busqueda
            :type query_id: int
            :returns: lista de tuplas de la forma [query_id, [(id, username, avatar)]]
            
            :raises: AttributeError
        """

        if username is not None:
            userkey = self.get_by_username(username, keys_only=True)
        elif userid is not None:
            userkey = db.Key.from_path(User.kind(), userid)
        else:
            raise AttributeError()
        from georemindme.paging import PagedQuery
        from models_acc import UserFollowingIndex
        followers = UserFollowingIndex.all().filter('following =',
                                                    userkey).order('-created')
        p = PagedQuery(followers, id=query_id)
        from georemindme.funcs import fetch_parents
        users = fetch_parents(p.fetch_page(page))
        return [
            p.id,
            [{
                'id': u.id,
                'username': u.username,
                'is_following': u.has_follower(userkey=userkey),
                'profile': u.profile
            } for u in users]
        ]
コード例 #3
0
ファイル: models.py プロジェクト: shafiabdul/GeoRemindMe_Web
 def get_activity_timeline(self, query_id=None):
     from models_acc import UserTimelineSystem, UserTimeline, UserTimelineFollowersIndex, UserTimelineSuggest
     from geovote.models import Comment, Vote
     from geoalert.models import Event
     from geolist.models import List
     # definir las consultas
     query_chrono = UserTimelineFollowersIndex.all().filter(
         'followers =', self.key()).order('-created')
     query_activity = UserTimelineSystem.all().filter(
         'user ='******'visible =', True).order('-modified')
     # recuperar cursores
     if query_id is not None and len(query_id) >= 2:
         cursor_chronology = query_id[0]
         cursor_activity = query_id[1]
         query_chrono = query_chrono.with_cursor(
             start_cursor=cursor_chronology)
         query_activity = query_activity.with_cursor(
             start_cursor=cursor_activity)
     else:
         cursor_activity = None
         cursor_chronology = None
     # let's go!
     timeline = []
     timeline_chrono = []
     activity_async = query_activity.run(
         config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE))
     chrono_async = query_chrono.run(config=datastore_query.QueryOptions(
         limit=TIMELINE_PAGE_SIZE))
     _go_chrono = True
     chrono = None
     for activity_timeline in activity_async:
         while _go_chrono:
             if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE:
                 _go_chrono = False
                 break
             if chrono is None:
                 try:
                     chrono = chrono_async.next()
                 except:
                     _go_chrono = False
                     break
             if chrono is not None and chrono.created > activity_timeline.modified:
                 timeline_chrono.append(chrono)
                 chrono = None
             else:
                 break
         timeline.append(activity_timeline)
         if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE:
             break
     # generar timeline
     timeline_chrono = fetch_parents(timeline_chrono)
     timeline = prefetch_refprops(timeline, UserTimeline.user)
     timeline_chrono = prefetch_refprops(timeline_chrono,
                                         UserTimeline.instance,
                                         UserTimeline.user)
     timeline.extend(timeline_chrono)
     #seguimos cargando por lotes todas las referencias
     from helpers_acc import _load_ref_instances
     instances = _load_ref_instances(timeline)
     timeline = [{
         'id':
         int(activity_timeline.id),
         'created':
         activity_timeline.created,
         'modified':
         activity_timeline.modified,
         'msg':
         activity_timeline.msg,
         'username':
         activity_timeline.user.username,
         'msg_id':
         activity_timeline.msg_id,
         'instance':
         instances.get(
             UserTimeline.instance.get_value_for_datastore(
                 activity_timeline), activity_timeline.instance),
         'has_voted':
         Vote.objects.user_has_voted(self, activity_timeline.instance.key())
         if activity_timeline.instance is not None else None,
         'vote_counter':
         Vote.objects.get_vote_counter(activity_timeline.instance.key())
         if activity_timeline.instance is not None else None,
         'comments':
         Comment.objects.get_by_instance(activity_timeline.instance,
                                         querier=self),
         'list':
         instances.get(
             UserTimelineSuggest.list_id.get_value_for_datastore(
                 activity_timeline), activity_timeline.list_id)
         if isinstance(activity_timeline, UserTimelineSuggest) else None,
         'status':
         activity_timeline.status
         if hasattr(activity_timeline, 'status') else None,
         'is_private':
         True,
         'user_follower':
         instances.get(
             UserTimeline.instance.get_value_for_datastore(
                 activity_timeline),
             activity_timeline.instance).has_follower(self) if hasattr(
                 instances.get(
                     UserTimeline.instance.get_value_for_datastore(
                         activity_timeline), activity_timeline.instance),
                 'has_follower') else None,
     } for activity_timeline in timeline]
     from operator import itemgetter
     timeline_sorted = sorted(timeline,
                              key=itemgetter('modified'),
                              reverse=True)
     chronology = [[query_chrono.cursor(),
                    query_activity.cursor()], timeline_sorted]
     return chronology
コード例 #4
0
 def load_suggestions_by_user_following(self, query_id, suggestions):
     from georemindme.funcs import fetch_parents
     suggestions = fetch_parents(suggestions)
     return [query_id, suggestions]
コード例 #5
0
        elif event._is_shared() and event.user_invited(querier):
            lists = ListSuggestion.objects.get_by_suggestion(event, querier)
            setattr(event, 'lists', lists)
            return event
        return None

    def get_by_user_following(self, user, page=1, query_id=None, async=False):
        if not isinstance(user, User):
            raise TypeError
        from models_indexes import SuggestionFollowersIndex
        q = SuggestionFollowersIndex.all().filter('keys =', user.key())
        p = PagedQuery(q, id=query_id)
        if async:
            return p.id, q.run()
        from georemindme.funcs import fetch_parents
        suggestions = fetch_parents(p.fetch_page(page))
        return [p.id, suggestions]

    def load_suggestions_by_user_following(self, query_id, suggestions):
        from georemindme.funcs import fetch_parents
        suggestions = fetch_parents(suggestions)
        return [query_id, suggestions]

    def get_nearest(self, location, radius=5000, querier=None):
        if not isinstance(location, db.GeoPt):
            location = db.GeoPt(location)
        import memcache
        client = memcache.mem.Client()
        if querier is not None and querier.is_authenticated():
            sugs = client.get('%ssug_nearest%s,%s_%s' % (
                memcache.version,
コード例 #6
0
ファイル: models.py プロジェクト: GeoRemindMe/GeoRemindMe_Web
 def get_activity_timeline(self, query_id=None):
     from models_acc import UserTimelineSystem, UserTimeline, UserTimelineFollowersIndex, UserTimelineSuggest
     from geovote.models import Comment, Vote
     from geoalert.models import Event
     from geolist.models import List
     # definir las consultas
     query_chrono = UserTimelineFollowersIndex.all().filter('followers =', self.key()).order('-created')
     query_activity = UserTimelineSystem.all().filter('user ='******'visible =', True).order('-modified')
     # recuperar cursores
     if query_id is not None and len(query_id)>=2:
         cursor_chronology = query_id[0]
         cursor_activity = query_id[1]
         query_chrono = query_chrono.with_cursor(start_cursor=cursor_chronology)
         query_activity = query_activity.with_cursor(start_cursor=cursor_activity)
     else:
         cursor_activity = None
         cursor_chronology = None
     # let's go!
     timeline = []
     timeline_chrono = []
     activity_async = query_activity.run(config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE))
     chrono_async = query_chrono.run(config=datastore_query.QueryOptions(limit=TIMELINE_PAGE_SIZE))
     _go_chrono = True
     chrono = None
     for activity_timeline in activity_async:
         while _go_chrono:
             if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE:
                 _go_chrono = False
                 break
             if chrono is None:
                 try:
                     chrono = chrono_async.next()
                 except:
                     _go_chrono = False
                     break
             if chrono is not None and chrono.created > activity_timeline.modified:
                 timeline_chrono.append(chrono)
                 chrono = None
             else:
                 break
         timeline.append(activity_timeline)
         if len(timeline) + len(timeline_chrono) >= TIMELINE_PAGE_SIZE:
             break
     # generar timeline
     timeline_chrono = fetch_parents(timeline_chrono)
     timeline = prefetch_refprops(timeline, UserTimeline.user)
     timeline_chrono = prefetch_refprops(timeline_chrono, UserTimeline.instance, UserTimeline.user)
     timeline.extend(timeline_chrono)
     #seguimos cargando por lotes todas las referencias
     from helpers_acc import _load_ref_instances
     instances = _load_ref_instances(timeline)
     timeline = [{
                 'id': int(activity_timeline.id),
                 'created': activity_timeline.created,
                 'modified': activity_timeline.modified,
                 'msg': activity_timeline.msg,
                 'username': activity_timeline.user.username,
                 'msg_id': activity_timeline.msg_id,
                 'instance': instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance),
                 'has_voted': Vote.objects.user_has_voted(self, activity_timeline.instance.key()) if activity_timeline.instance is not None else None,
                 'vote_counter': Vote.objects.get_vote_counter(activity_timeline.instance.key()) if activity_timeline.instance is not None else None,
                 'comments': Comment.objects.get_by_instance(activity_timeline.instance, querier=self),
                 'list': instances.get(UserTimelineSuggest.list_id.get_value_for_datastore(activity_timeline), activity_timeline.list_id)
                                 if isinstance(activity_timeline, UserTimelineSuggest) else None,
                 'status': activity_timeline.status if hasattr(activity_timeline, 'status') else None,
                 'is_private': True,
                 'user_follower': instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance).has_follower(self)
                     if hasattr(instances.get(UserTimeline.instance.get_value_for_datastore(activity_timeline), activity_timeline.instance), 'has_follower')
                     else None,
                 } for activity_timeline in timeline]
     from operator import itemgetter
     timeline_sorted = sorted(timeline, key=itemgetter('modified'), reverse=True)
     chronology = [[query_chrono.cursor(), query_activity.cursor()], timeline_sorted]
     return chronology