示例#1
0
    def anno_list(self, request):
        """
        Exposes an API endpoint to retrieve a list of anno.
        """
        user = auth_user(self.request_state.headers)
        limit = 10
        if request.limit is not None:
            limit = request.limit

        curs = None
        if request.cursor is not None:
            try:
                curs = Cursor(urlsafe=request.cursor)
            except BadValueError:
                raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)

        select_projection = None
        if request.select is not None:
            select_projection = request.select.split(',')

        if request.query_type == 'by_created':
            return Anno.query_by_app_by_created(request.app, limit, select_projection, curs)
        elif request.query_type == 'by_vote_count':
            return Anno.query_by_vote_count(request.app)
        elif request.query_type == 'by_flag_count':
            return Anno.query_by_flag_count(request.app)
        elif request.query_type == 'by_activity_count':
            return Anno.query_by_activity_count(request.app)
        elif request.query_type == 'by_last_activity':
            return Anno.query_by_last_activity(request.app)
        elif request.query_type == 'by_country':
            return Anno.query_by_country(request.app)
        else:
            return Anno.query_by_page(limit, select_projection, curs)
示例#2
0
    def anno_list(self, request):
        """
        Exposes an API endpoint to retrieve a list of anno.
        """
        user = auth_user(self.request_state.headers)

        limit = 10
        if request.limit is not None:
            limit = request.limit

        is_plugin = request.is_plugin or False

        curs = None
        if request.cursor is not None:
            try:
                curs = Cursor(urlsafe=request.cursor)
            except BadValueError:
                raise endpoints.BadRequestException('Invalid cursor %s.' % request.cursor)

        select_projection = None
        if request.select is not None:
            select_projection = request.select.split(',')

        if request.query_type == AnnoQueryType.CREATED:
            return Anno.query_by_app_by_created(request.app, limit, select_projection, curs, user)
        elif request.query_type == AnnoQueryType.VOTE_COUNT:
            return Anno.query_by_vote_count(request.app, user)
        elif request.query_type == AnnoQueryType.FLAG_COUNT:
            return Anno.query_by_flag_count(request.app, user)
        elif request.query_type == AnnoQueryType.ACTIVITY_COUNT:
            return Anno.query_by_activity_count(request.app, user)
        elif request.query_type == AnnoQueryType.LAST_ACTIVITY:
            return Anno.query_by_last_activity(request.app, user)
        elif request.query_type == AnnoQueryType.COUNTRY:
            return Anno.query_by_country(request.app, user)
        elif request.query_type == AnnoQueryType.COMMUNITY:
            community = Community.get_by_id(request.community)
            return Anno.query_by_community(community, limit, select_projection, curs, user)
        elif request.query_type == AnnoQueryType.APP:
            app = AppInfo.get(request.app)
            return Anno.query_by_app(app, limit, select_projection, curs, user)
        else:
            return Anno.query_by_page(limit, select_projection, curs, user, is_plugin)