コード例 #1
0
    def feed_sequence_update_alltime(self):

        logging.info("In feed_sequence_update_alltime")
        urlsafe_cursor = self.request.get('cursor')
        cursor_from_url = Cursor(
            urlsafe=urlsafe_cursor) if urlsafe_cursor else None
        logging.info("Cursor in start is: {}".format(cursor_from_url))

        #Define query here
        gql_query_text = 'Select * From TestSequences'

        #Execute query
        query_o = ndb.gql(gql_query_text)
        BATCH_SIZE = 500
        results, next_cursor, more = query_o.fetch_page(
            BATCH_SIZE, start_cursor=cursor_from_url)

        if more:
            pass
        if next_cursor:
            pass

        if not results:
            logging.info("feed_sequence_update_task: all done")
            return

        #Calling fn to insert data in FeedSequence
        record_type = 'alltime'
        FeedModelCheck.add_feeds_sequences_records(self, results, record_type)

        cursor = query_o.fetch()
        taskqueue.add(url='/admin/feed/add-top-searches-alltime',
                      params={'cursor': cursor})
        logging.info("Exiting feed_sequence_update_alltime")
        return
コード例 #2
0
    def posts_list(self, request):
        """
        List posts
        """
        limit = min(request.limit, MAX_LIMIT)
        start_cursor = Cursor(urlsafe=request.next_token)

        query = Post.query()
        posts, next_cursor, more = query.fetch_page(limit,
                                                    start_cursor=start_cursor,
                                                    batch_size=limit)

        next_token = next_cursor.urlsafe() if next_cursor and more else None
        resp_posts = [self._post_from_db(post) for post in posts]

        return PostsCollection(posts=resp_posts, next_token=next_token)
コード例 #3
0
    def paginate_queryset(self, queryset, request, view=None):
        """
        Paginate a queryset if required, either returning a
        page object, or `None` if pagination is not configured for this view.
        """
        self.count = queryset.count()
        self.request = request
        try:
            self.page, self.next_page, self.has_next = queryset.fetch_page(
                self.get_page_size(request),
                start_cursor=Cursor(urlsafe=self.get_page_token()))
        except InvalidPage:
            raise NotFound('Requested page not found')
        except BadValueError as err:
            raise BadRequest(str(err))

        return list(self.page)
コード例 #4
0
    def get(self):
        url_title = self.request.get('url_title')

        curs = Cursor(urlsafe=self.request.get('cursor'))
        page_size = 60
        if ws.debug:
            page_size = 1
        companies, next_curs, more = Company.randomOrder(1).fetch_page(page_size, start_cursor=curs)

        if more and next_curs:
            next_page_cursor = next_curs.urlsafe()
        else:
            next_page_cursor = None
        extraParams = {
            'companies': companies,
            'next_page_cursor': next_page_cursor,
            'url_title': url_title,
        }
        self.render('templates/companies.jinja2', extraParams)
コード例 #5
0
ファイル: rest_gae.py プロジェクト: justingrayston/rest_gae
        else:
            try:
                limit = int(self.request.GET.get('limit'))
                if limit <= 0: raise ValueError('Limit cannot be zero or less')
            except ValueError, exc:
                # Invalid limit value
                raise RESTException('Invalid "limit" parameter - %s' %
                                    self.request.GET.get('limit'))

        if not self.request.GET.get('cursor'):
            # Fetch results from scratch
            cursor = None
        else:
            # Continue a previous query
            try:
                cursor = Cursor(urlsafe=self.request.GET.get('cursor'))
            except BadValueError, exc:
                raise RESTException('Invalid "cursor" argument - %s' %
                                    self.request.GET.get('cursor'))

        try:
            (results, cursor,
             more_available) = query.fetch_page(limit, start_cursor=cursor)
        except BadRequestError, exc:
            # This happens when we're using an existing cursor and the other query arguments were messed with
            raise RESTException('Invalid "cursor" argument - %s' %
                                self.request.GET.get('cursor'))

        if not more_available:
            cursor = None