Esempio n. 1
0
 def get(self):
     """
     Render the About page from the common template.
     """
     template = JINJA_ENVIRONMENT.get_template('about.html')
     template_values = get_template_values()
     self.response.write(template.render(template_values))
Esempio n. 2
0
    def _get_page_from_key(self, plaque_key=None):
        """
        Put the single plaque into a list for rendering so that the common map
        functionality can be used unchanged. Attempt to serve a valid plaque,
        but if the inputs are completely messed up, serve the oldest plaque.
        """

        # If it's memecached, use that:
        is_admin = users.is_current_user_admin()
        memcache_name = 'plaque_%s_%s' % (plaque_key, is_admin)
        page_text = memcache.get(memcache_name)
        if page_text is not None:
            return page_text

        # If page is not memcached, get the plaque from the db:
        plaque = self._get_plaque_from_key(plaque_key)

        # If that didn't find anything, serve the default couldn't-find-it
        # plaque (currently hacked in as the earliest plaque):
        if plaque is None:
            earliest_plaque = Plaque.query(Plaque.approved == True).order(
                Plaque.created_on).get()
            self.redirect(earliest_plaque.title_page_url)
            return

        template_values = get_template_values(plaques=[plaque])

        template = JINJA_ENVIRONMENT.get_template('one.html')
        page_text = template.render(template_values)
        memcache_status = memcache.set(memcache_name, page_text)
        if not memcache_status:
            logging.debug("memcache.set for _get_page_from_key failed for %s" %
                          memcache_name)

        return page_text
Esempio n. 3
0
    def get(self, tag, view_all=False):
        """
        View plaques with a given tag on a grid.
        """
        memcache_name = 'plaques_tag_%s' % tag
        page_text = memcache.get(memcache_name)

        if page_text is None:
            query = Plaque.query()
            if not view_all:
                query = query.filter(Plaque.approved == True)

            # TODO: NDB cursor pagination?
            plaques = query.filter(
                Plaque.tags == tag).order(-Plaque.created_on).fetch(
                    limit=DEF_NUM_PER_PAGE)

            template = JINJA_ENVIRONMENT.get_template('all.html')
            template_values = get_template_values(plaques=plaques)
            page_text = template.render(template_values)
            memcache_status = memcache.set(memcache_name, page_text)
            if not memcache_status:
                logging.debug("ViewTag memcache.set for %s failed" %
                              memcache_name)
        else:
            logging.debug("ViewTag memcache.get worked for %s" % memcache_name)

        self.response.write(page_text)
Esempio n. 4
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
Esempio n. 5
0
 def _write_geo_page(self, geo_plaques_approved, lat, lng):
     template = JINJA_ENVIRONMENT.get_template('all.html')
     template_values = get_template_values(plaques=geo_plaques_approved,
                                           mapcenter={
                                               'lat': lat,
                                               'lng': lng
                                           })
     self.response.write(template.render(template_values))
Esempio n. 6
0
    def _serve_form(self, redir):
        maptext = 'Click the map, or type a search here'
        step1text = 'Click the map to pick where to search'
        if redir:
            step1text = '<span style="color:red">%s</span>' % step1text

        template_values = get_template_values(maptext=maptext,
                                              step1text=step1text)
        template = JINJA_ENVIRONMENT.get_template('geosearch.html')
        self.response.write(template.render(template_values))
Esempio n. 7
0
    def write_pending(self, plaques):

        user = users.get_current_user()
        name = "anon" if user is None else user.nickname()
        logging.info("User %s is viewing pending plaques %s" % (name, plaques))

        template = JINJA_ENVIRONMENT.get_template('all.html')
        template_values = get_template_values(plaques=plaques, is_pending=True)
        template_text = template.render(template_values)
        self.response.write(template_text)
Esempio n. 8
0
    def get(self, message=None):
        maptext = "Click the plaque's location on the map, or search " + \
                  "for it, or enter its lat/lng location"
        template_values = get_template_values(maptext=maptext,
                                              mapzoom=10,
                                              page_title="Add Plaque")
        message = self._get_message(message)
        if message is not None:
            template_values['message'] = message
        message = self.request.get('message')

        template = JINJA_ENVIRONMENT.get_template('add.html')
        self.response.write(template.render(template_values))
Esempio n. 9
0
    def get(self, search_term=None):
        if search_term is None:
            plaques = []
        else:
            # TODO: NDB cursor pagination?
            plaques = self._search_plaques(search_term)

            # Allow admin to see unpublished plaques, hide these from others
            if not users.is_current_user_admin():
                plaques = [p for p in plaques if p.approved]

        template = JINJA_ENVIRONMENT.get_template('all.html')
        template_values = get_template_values(plaques=plaques)
        self.response.write(template.render(template_values))
Esempio n. 10
0
    def get(self, search_term=None):
        logging.info(
            "SearchPlaquesPending: search_term: {}".format(search_term))

        logging.info("SearchPlaquesPending: IS admin")
        # Unpublished plaques matching the search term:
        plaques = self._search_plaques(search_term)
        logging.info("SearchPlaquesPending: number of plaques {}".format(
            len(plaques)))
        plaques = [p for p in plaques if not p.approved]
        logging.info(
            "SearchPlaquesPending: number of not-approved plaques {}".format(
                len(plaques)))

        template = JINJA_ENVIRONMENT.get_template('all.html')
        template_values = get_template_values(plaques=plaques)
        self.response.write(template.render(template_values))
Esempio n. 11
0
    def get(self, lat=None, lng=None, zoom=None):

        template_values = get_template_values(bigmap=True)
        query = Plaque.query()
        num_plaques = query.filter(Plaque.approved == True).count()
        template_values['counts'] = num_plaques
        logging.debug(template_values)
        if lat is not None and lng is not None:
            template_values['bigmap_center'] = True
            template_values['bigmap_lat'] = lat
            template_values['bigmap_lng'] = lng

            if zoom is not None:
                template_values['bigmap_zoom'] = zoom

        template = JINJA_ENVIRONMENT.get_template(self.template_file)
        template_text = template.render(template_values)
        self.response.write(template_text)
Esempio n. 12
0
 def get(self):
     template = JINJA_ENVIRONMENT.get_template(self.template_file)
     template_values = get_template_values()
     template_text = template.render(template_values)
     self.response.write(template_text)