class ZonesController(BaseController): readonly = True # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, Zone, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, Zone) # filter = and_(default_filter, Zone.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) if format != 'json': abort(404) return self.protocol.read(request) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) #@geojsonify #def create(self): # """POST /: Create a new feature.""" # return self.protocol.create(request, response) # #@geojsonify #def update(self, id): # """PUT /id: Update an existing feature.""" # return self.protocol.update(request, response, id) # #def delete(self, id): # """DELETE /id: Delete an existing feature.""" # return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
class BicycleRentalController(BaseController): readonly = False # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, BicycleRental, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, BicycleRental) # filter = and_(default_filter, BicycleRental.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) if format != 'json': abort(404) return self.protocol.read(request) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) @geojsonify def create(self): """POST /: Create a new feature.""" return self.protocol.create(request, response) @geojsonify def update(self, id): """PUT /id: Update an existing feature.""" return self.protocol.update(request, response, id) def delete(self, id): """DELETE /id: Delete an existing feature.""" return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
def test_protocol_read_all(self): """Return all features""" proto = Protocol(session, Spot) collection = proto.read(FakeRequest({})) ok_(collection is not None) ok_(isinstance(collection, FeatureCollection)) eq_(len(collection.features), 9)
def test_protocol_read_all(self): """Return all features""" proto = Protocol(session, Spot) collection = proto.read(FakeRequest({})) ok_(collection is not None) ok_(isinstance(collection, FeatureCollection)) eq_(len(collection.features), 9)
def test_protocol_read_one(self): """Return one feature""" proto = Protocol(session, Spot) feature = proto.read(FakeRequest({}), id=1) ok_(feature is not None) ok_(isinstance(feature, Feature)) eq_(feature.id, 1) eq_(feature.geometry.coordinates, (0.0, 0.0)) eq_(feature.properties["spot_height"], 420.39999999999998)
def test_protocol_read_one(self): """Return one feature""" proto = Protocol(session, Spot) feature = proto.read(FakeRequest({}), id=1) ok_(feature is not None) ok_(isinstance(feature, Feature)) eq_(feature.id, 1) eq_(feature.geometry.coordinates, (0.0, 0.0)) eq_(feature.properties["spot_height"], 420.39999999999998)
def test_protocol_read_one_null(self): """Return one null feature""" proto = Protocol(session, Spot) feature = proto.read(FakeRequest({}), id=9) ok_(feature is not None) ok_(isinstance(feature, Feature)) eq_(feature.id, 9) # make use of __geo_interface__ property since 'geometry' # value is not the same in various versions of geojson lib ok_(feature.__geo_interface__['geometry'] is None) ok_(feature.__geo_interface__['bbox'] is None)
def test_protocol_read_one_null(self): """Return one null feature""" proto = Protocol(session, Spot) feature = proto.read(FakeRequest({}), id=9) ok_(feature is not None) ok_(isinstance(feature, Feature)) eq_(feature.id, 9) # make use of __geo_interface__ property since 'geometry' # value is not the same in various versions of geojson lib ok_(feature.__geo_interface__['geometry'] is None) ok_(feature.__geo_interface__['bbox'] is None)
class BroadbandSpeedsController(BaseController): readonly = False # if set to True, only GET is supported def __init__(self): self.protocol = Protocol(Session, BroadbandSpeed, self.readonly) @geojsonify def index(self, format='json'): """GET /: return all features.""" # If no filter argument is passed to the protocol index method # then the default MapFish filter is used. # # If you need your own filter with application-specific params # taken into acount, create your own filter and pass it to the # protocol read method. # # E.g. # # from sqlalchemy.sql import and_ # # default_filter = create_default_filter(request, BroadbandSpeed) # filter = and_(default_filter, BroadbandSpeed.columname.ilike('%value%')) # return self.protocol.read(request, filter=filter) default_filter = create_default_filter(request, BroadbandSpeed) if "zones_f" in request.params: #zones will be a javascript list zones_q = request.params["zones_f"].split(",") #zones = Session.query(functions.geometry_type(functions.collect(Zone.geom))).filter(and_(Zone.zone_general.in_(zones_q), # Zone.geom != None)).scalar() zones = Session.query(functions.union(Zone.geom)).filter(Zone.zone_general.in_(zones_q)).first() filter = and_(default_filter, BroadbandSpeed.geom.within(zones)) else: filter = default_filter if format != 'json': abort(404) return self.protocol.read(request, filter=filter) @geojsonify def show(self, id, format='json'): """GET /id: Show a specific feature.""" if format != 'json': abort(404) return self.protocol.read(request, response, id=id) #@geojsonify #def create(self): # """POST /: Create a new feature.""" # return self.protocol.create(request, response) # #@geojsonify #def update(self, id): # """PUT /id: Update an existing feature.""" # return self.protocol.update(request, response, id) # #def delete(self, id): # """DELETE /id: Delete an existing feature.""" # return self.protocol.delete(request, response, id) def count(self): """GET /count: Count all features.""" return self.protocol.count(request)
def test_protocol_read_one_fails(self): """Try to get a single point with a wrong primary key""" proto = Protocol(session, Spot) proto.read(FakeRequest({}), id=-1)
def test_protocol_read_one_fails(self): """Try to get a single point with a wrong primary key""" proto = Protocol(session, Spot) proto.read(FakeRequest({}), id=-1)