def point_update(request): # first try to load the point that should be updated try: # try to cast the given id to an integer id = int(request.matchdict['id']) except ValueError: raise HTTPBadRequest() try: # load the point with the given id point = DBSession.query(Point).filter(Point.id == id).one() except NoResultFound: raise HTTPNotFound() # get the new values title = request.POST.get('title', '') description = request.POST.get('description', '') try: # try to get the input parameters lon = float(request.POST.get('lon')) lat = float(request.POST.get('lat')) except ValueError: raise HTTPBadRequest() # then set the new values on the point point.title = title point.description = description point.geom = from_shape(PointShape(lon, lat), srid=4326) # the point will automatically be flushed (updated in the database) return to_geojson(point)
def points(request): points = DBSession.query(Point).all() points_geojson = [to_geojson(point) for point in points] return { 'type': 'FeatureCollection', 'features': points_geojson }
def point(request): try: # try to cast the given id to an integer id = int(request.matchdict['id']) except ValueError: raise HTTPBadRequest() try: # load the point with the given id point = DBSession.query(Point).filter(Point.id == id).one() except NoResultFound: raise HTTPNotFound() return to_geojson(point)