예제 #1
0
    def _get_template_values(self, per_page, cursor_urlsafe, is_random,
                             is_featured):
        if is_random:
            plaques = []
            cursor_urlsafe = None
            more = False
            for i in range(per_page):
                plaques.append(get_random_plaque())
        else:
            plaques, next_cursor, more = Plaque.fetch_page(
                per_page, start_cursor=cursor_urlsafe, urlsafe=True)

            if next_cursor is None:
                cursor_urlsafe = ''
            else:
                cursor_urlsafe = next_cursor.urlsafe()

        template_values = get_template_values(
            plaques=plaques, next_cursor_urlsafe=cursor_urlsafe, more=more)
        if is_featured:
            featured = get_featured()
            template_values['featured_plaque'] = featured
            fake = FakePlaqueForRootUrlPreviews()
            template_values['fake_plaque_for_root_url_previews'] = fake

        return template_values
예제 #2
0
    def _json_for_all(self, summary=True):
        plaques_all = []
        num = 1000
        more = True
        cursor = None
        while more:
            plaques, cursor, more = Plaque.fetch_page(num=num,
                                                      start_cursor=cursor,
                                                      urlsafe=False)
            plaques_all.extend(plaques)
            logging.info("tot: %s, current: %s, cursor: %s, more?: %s" %
                         (len(plaques_all), len(plaques_all), cursor, more))

        json_output = self._plaques_to_json(plaques_all, summary)
        return json_output