def create_details_response(self, res): if res is None: raise cherrypy.NotFound() loctags = TagStore.make_localized(res['tags'], cherrypy.request.locales) cfg = cherrypy.request.app.config ret = api.common.RouteDict(res) ret['type'] = res['type'] if res.has_key('type') else 'relation' ret['symbol_url'] = '%s/symbols/%s/%s.svg' % ( cfg['Global']['MEDIA_URL'], cfg['Global']['BASENAME'], str(res['symbol'])) ret['mapped_length'] = int(res['length']) ret.add_if('official_length', loctags.get_length('distance', 'length', unit='m')) for tag in ('operator', 'note', 'description'): ret.add_if(tag, loctags.get(tag)) ret.add_if('url', loctags.get_url()) ret.add_if('wikipedia', loctags.get_wikipedia_tags()) ret['bbox'] = to_shape(res['bbox']).bounds if hasattr(self, '_hierarchy_list'): for name, val in (('subroutes', True), ('superroutes', False)): ret.add_if(name, self._hierarchy_list(ret['id'], val)) ret['tags'] = res['tags'] return ret
def _add_details(self, row, locales): loctags = TagStore.make_localized(row['tags'], locales) self.content['mapped_length'] = int(row['length']) self._add_optional('official_length', row, None, loctags.get_length('distance', 'length', unit='m')) for tag in ('operator', 'note', 'description'): self._add_optional(tag, row, None, loctags.get(tag)) self._add_optional('url', row, None, loctags.get_url()) self._add_optional('wikipedia', row, None, loctags.get_wikipedia_tags() or None) self.content['bbox'] = to_shape(row['bbox']).bounds self.content['tags'] = row['tags']
def index(self, oid, **params): cfg = cherrypy.request.app.config mapdb = cfg['DB']['map'] r = mapdb.tables.guideposts.data o = mapdb.osmdata.node.data sel = sa.select([r.c.name, r.c.ele, r.c.geom.ST_X().label('lon'), r.c.geom.ST_Y().label('lat'), o.c.tags])\ .where(r.c.id == oid)\ .where(o.c.id == oid) res = cherrypy.request.db.execute(sel).first() if res is None: raise cherrypy.NotFound() ret = OrderedDict() loctags = TagStore.make_localized(res['tags'], cherrypy.request.locales) ret['type'] = 'guidepost' ret['id'] = oid if 'name' in loctags: ret['name'] = loctags['name'] if res['name'] and res['name'] != ret['name']: ret['local_name'] = res['name'] if res['ele'] is not None: ret['ele'] = loctags.get_length('ele', unit='m', default='m') for tag in ('ref', 'operator', 'description', 'note'): if tag in loctags: ret[tag] = loctags[tag] if 'image' in loctags: imgurl = loctags['image'] if imgurl.startswith('http://') or imgurl.startswith('https://'): # HTML injection paranoia imgurl.replace('"', '%22') imgurl.replace("'", '%27') ret['image'] = imgurl ret['tags'] = res['tags'] ret['y'] = res['lat'] ret['x'] = res['lon'] return ret
def add_row_data(self, row, locales): loctags = TagStore.make_localized(row['tags'], locales) if 'name' in loctags: self.content['name'] = loctags['name'] if row['name'] and row['name'] != self.content['name']: self.content['local_name'] = row['name'] self.add_if('ele', row['ele']) for tag in ('ref', 'operator', 'description', 'note'): self.add_if(tag, loctags.get(tag)) self.add_if('image', loctags.get_url(keys=['image'])) for key in ('tags', 'x', 'y'): self.content[key] = row[key] return self