本文整理汇总了Python中mapfish.protocol.Protocol.create方法的典型用法代码示例。如果您正苦于以下问题:Python Protocol.create方法的具体用法?Python Protocol.create怎么用?Python Protocol.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mapfish.protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_protocol_create_fails
# 需要导入模块: from mapfish.protocol import Protocol [as 别名]
# 或者: from mapfish.protocol.Protocol import create [as 别名]
def test_protocol_create_fails(self):
"""Try to create a feature without geometry"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}}]}'
proto.create(request, FakeResponse())
示例2: test_protocol_create
# 需要导入模块: from mapfish.protocol import Protocol [as 别名]
# 或者: from mapfish.protocol.Protocol import create [as 别名]
def test_protocol_create(self):
from mapfish.protocol import Protocol
proto = Protocol(Session, MappedClass)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}, {"type": "Feature", "properties": {"text": "foo"}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
response = FakeResponse()
proto.create(request, response, execute=False)
assert response.status == 201
assert len(Session.new) == 2
for obj in Session.new:
assert obj["text"] == "foo"
assert obj._mf_shape.x == 45
assert obj._mf_shape.y == 5
Session.rollback()
示例3: test_protocol_create_and_update
# 需要导入模块: from mapfish.protocol import Protocol [as 别名]
# 或者: from mapfish.protocol.Protocol import create [as 别名]
def test_protocol_create_and_update(self):
"""Create a new point and also update an already existing point"""
old_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [\
{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}},\
{"type": "Feature", "id": ' + str(old_spot.spot_id) + ', "properties": {}, "geometry": {"type": "Point", "coordinates": [1, 1]}}]}'
response = FakeResponse()
collection = proto.create(request, response)
eq_(response.status, 201)
eq_(len(collection.features), 2)
feature0 = collection.features[0]
eq_(feature0.id, 10)
eq_(feature0.geometry.coordinates, (45.0, 5.0))
eq_(feature0.properties["spot_height"], 12)
feature1 = collection.features[1]
eq_(feature1.id, old_spot.spot_id)
eq_(feature1.geometry.coordinates, (1, 1))
new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
ok_(new_spot is not None)
eq_(session.scalar(new_spot.spot_location.wkt), u'POINT(45 5)')
updated_spot = session.query(Spot).filter(Spot.spot_height==102.34).one()
ok_(updated_spot is not None)
ok_(old_spot is updated_spot)
eq_(updated_spot.spot_height, 102.34)
eq_(session.scalar(updated_spot.spot_location.wkt), u'POINT(1 1)')
示例4: ParkingMetersController
# 需要导入模块: from mapfish.protocol import Protocol [as 别名]
# 或者: from mapfish.protocol.Protocol import create [as 别名]
class ParkingMetersController(BaseController):
readonly = True # if set to True, only GET is supported
def __init__(self):
self.protocol = Protocol(Session, ParkingMeter, 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, ParkingMeter)
# filter = and_(default_filter, ParkingMeter.columname.ilike('%value%'))
# return self.protocol.read(request, filter=filter)
if format != 'json':
abort(404)
response.headers['Access-Control-Allow-Origin'] = 'http://localhost:8000';
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)
示例5: test_protocol_create
# 需要导入模块: from mapfish.protocol import Protocol [as 别名]
# 或者: from mapfish.protocol.Protocol import create [as 别名]
def test_protocol_create(self):
"""Create a new point"""
proto = Protocol(session, Spot)
request = FakeRequest({})
request.body = '{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"spot_height": 12.0}, "geometry": {"type": "Point", "coordinates": [45, 5]}}]}'
response = FakeResponse()
collection = proto.create(request, response)
eq_(response.status, 201)
eq_(len(collection.features), 1)
feature0 = collection.features[0]
eq_(feature0.id, 10)
eq_(feature0.geometry.coordinates, (45.0, 5.0))
eq_(feature0.properties["spot_height"], 12)
new_spot = session.query(Spot).filter(Spot.spot_height==12.0).one()
ok_(new_spot is not None)
eq_(session.scalar(new_spot.spot_location.wkt), u'POINT (45.0 5.0)')