Use DictCursor for events query
This commit is contained in:
parent
bc731e686c
commit
49523bd566
1 changed files with 15 additions and 10 deletions
25
backend.py
25
backend.py
|
@ -39,18 +39,23 @@ class StatsResource(object):
|
||||||
|
|
||||||
|
|
||||||
class EventsResource(object):
|
class EventsResource(object):
|
||||||
|
|
||||||
|
def row_to_feature(self, row):
|
||||||
|
return {
|
||||||
|
"type": "Feature",
|
||||||
|
"geometry": json.loads(row['geometry']),
|
||||||
|
"id": row['events_id'],
|
||||||
|
"properties": row['events_tags']
|
||||||
|
}
|
||||||
|
|
||||||
def on_get(self, req, resp):
|
def on_get(self, req, resp):
|
||||||
db = db_connect()
|
db = db_connect()
|
||||||
cur = db.cursor()
|
cur = db.cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
# get event geojson Feature
|
cur.execute("SELECT events_id, events_tags, st_asgeojson(geom) as geometry FROM events JOIN geo ON (hash=events_geo)")
|
||||||
cur.execute("""
|
resp.body = json.dumps({
|
||||||
SELECT format('{"type":"Feature", "id": "'|| events_id::text ||'", "properties": '|| events_tags::text ||', "geometry":'|| st_asgeojson(geom)) ||' }'
|
"type": "FeatureCollection",
|
||||||
FROM events
|
"features": [self.row_to_feature(r) for r in cur.fetchall()]
|
||||||
JOIN geo ON (hash=events_geo)""");
|
})
|
||||||
resp.body = """{"type": "FeatureCollection","features": [
|
|
||||||
"""+""",
|
|
||||||
""".join([x[0] for x in cur.fetchall()])+"""
|
|
||||||
]}"""
|
|
||||||
resp.status = falcon.HTTP_200
|
resp.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue