# HG changeset patch # User Thierry Florac # Date 1611758306 -3600 # Node ID 31687784fa160c6e61bc4a3a0154bf0bf3757ac0 # Parent d9ee6f8ddb7694ceb7dee7ae5b121274dd6e90ce Added schema fields factories diff -r d9ee6f8ddb76 -r 31687784fa16 src/pyams_gis/zmi/widget/area.py --- a/src/pyams_gis/zmi/widget/area.py Wed Jan 27 15:37:20 2021 +0100 +++ b/src/pyams_gis/zmi/widget/area.py Wed Jan 27 15:38:26 2021 +0100 @@ -32,21 +32,15 @@ @adapter_config(name=getIfName(IGeoArea), - context=(Interface, IFormLayer, IForm, IGeoAreaWidget), provides=IObjectFactory) -class GeoAreaObjectFactory(object): + context=(Interface, IFormLayer, IForm, IGeoAreaWidget), + provides=IObjectFactory) +def geo_area_object_factory(*args, **kwargs): """GeoArea object factory""" - - def __init__(self, context, request, form, widget): - self.context = context - self.request = request - self.form = form - self.widget = widget - - def __call__(self, data): - return GeoArea() + return GeoArea -@widgettemplate_config(mode='input', template='templates/geoarea-input.pt', layer=IFormLayer) +@widgettemplate_config(mode='input', + template='templates/geoarea-input.pt', layer=IFormLayer) @implementer_only(IGeoAreaWidget) class GeoAreaWidget(ObjectWidget): """GeoArea widget""" @@ -56,19 +50,27 @@ widgets = self.widgets x1 = widgets['x1'] x1.input_css_class = 'col-md-2' - x1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} + x1.object_data = { + 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' + } alsoProvides(x1, IObjectData) x2 = widgets['x2'] x2.input_css_class = 'col-md-2' - x2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} + x2.object_data = { + 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' + } alsoProvides(x2, IObjectData) y1 = widgets['y1'] y1.input_css_class = 'col-md-2' - y1.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} + y1.object_data = { + 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' + } alsoProvides(y1, IObjectData) y2 = widgets['y2'] y2.input_css_class = 'col-md-2' - y2.object_data = {'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate'} + y2.object_data = { + 'ams-change-handler': 'PyAMS_GIS.area.changedCoordinate' + } alsoProvides(y2, IObjectData) projection = widgets['projection'] projection.object_data = { @@ -82,19 +84,24 @@ def wgs_coordinates(self): value = self.field.get(self.field.interface(self.context)) if not value: - return json.dumps({'x1': None, - 'y1': None, - 'x2': None, - 'y2': None}) + return json.dumps({ + 'x1': None, + 'y1': None, + 'x2': None, + 'y2': None + }) else: point1, point2 = value.wgs_coordinates - return json.dumps({'x1': float(point1[0]), - 'y1': float(point1[1]), - 'x2': float(point2[0]), - 'y2': float(point2[1])}) + return json.dumps({ + 'x1': float(point1[0]), + 'y1': float(point1[1]), + 'x2': float(point2[0]), + 'y2': float(point2[1]) + }) -@adapter_config(context=(IGeoAreaField, IFormLayer), provides=IFieldWidget) +@adapter_config(context=(IGeoAreaField, IFormLayer), + provides=IFieldWidget) def GeoAreaFieldWidget(field, request): """GeoArea field widget factory""" return FieldWidget(field, GeoAreaWidget(request)) diff -r d9ee6f8ddb76 -r 31687784fa16 src/pyams_gis/zmi/widget/point.py --- a/src/pyams_gis/zmi/widget/point.py Wed Jan 27 15:37:20 2021 +0100 +++ b/src/pyams_gis/zmi/widget/point.py Wed Jan 27 15:38:26 2021 +0100 @@ -32,21 +32,15 @@ @adapter_config(name=getIfName(IGeoPoint), - context=(Interface, IFormLayer, IForm, IGeoPointWidget), provides=IObjectFactory) -class GeoPointObjectFactory(object): + context=(Interface, IFormLayer, IForm, IGeoPointWidget), + provides=IObjectFactory) +def geo_point_object_widget_factory(*args, **kwargs): """GeoPointZ object factory""" - - def __init__(self, context, request, form, widget): - self.context = context - self.request = request - self.form = form - self.widget = widget - - def __call__(self, data): - return GeoPoint() + return GeoPoint -@widgettemplate_config(mode='input', template='templates/geopoint-input.pt', layer=IFormLayer) +@widgettemplate_config(mode='input', + template='templates/geopoint-input.pt', layer=IFormLayer) @implementer_only(IGeoPointWidget) class GeoPointWidget(ObjectWidget): """GeoPoint widget""" @@ -57,53 +51,59 @@ longitude = widgets['longitude'] longitude.label_css_class = 'control-label col-md-3' longitude.input_css_class = 'col-md-2' - longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} + longitude.object_data = { + 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' + } alsoProvides(longitude, IObjectData) latitude = widgets['latitude'] latitude.label_css_class = 'control-label col-md-3' latitude.input_css_class = 'col-md-2' - latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} + latitude.object_data = { + 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' + } alsoProvides(latitude, IObjectData) projection = widgets['projection'] projection.label_css_class = 'control-label col-md-3' projection.input_css_class = 'col-md-9' - projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}} + projection.object_data = { + 'ams-events-handlers': { + 'change.select2': 'PyAMS_GIS.position.changedProjection' + } + } alsoProvides(projection, IObjectData) @property def wgs_coordinates(self): value = self.field.get(self.field.interface(self.context)) if not value: - return json.dumps({'longitude': None, - 'latitude': None}) - else: - point = value.wgs_coordinates - return json.dumps({'longitude': float(point[0]), - 'latitude': float(point[1])}) + return json.dumps({ + 'longitude': None, + 'latitude': None + }) + # else: + point = value.wgs_coordinates + return json.dumps({ + 'longitude': float(point[0]), + 'latitude': float(point[1]) + }) -@adapter_config(context=(IGeoPointField, IFormLayer), provides=IFieldWidget) +@adapter_config(context=(IGeoPointField, IFormLayer), + provides=IFieldWidget) def GeoPointFieldWidget(field, request): """GeoPoint field widget factory""" return FieldWidget(field, GeoPointWidget(request)) @adapter_config(name=getIfName(IGeoPointZ), - context=(Interface, IFormLayer, IForm, IGeoPointZWidget), provides=IObjectFactory) -class GeoPointZObjectFactory(object): - """GeoPointZ object factory""" - - def __init__(self, context, request, form, widget): - self.context = context - self.request = request - self.form = form - self.widget = widget - - def __call__(self, data): - return GeoPointZ() + context=(Interface, IFormLayer, IForm, IGeoPointZWidget), + provides=IObjectFactory) +def geo_pointz_object_factory(*args, **kwargs): + return GeoPointZ -@widgettemplate_config(mode='input', template='templates/geopoint-input.pt', layer=IFormLayer) +@widgettemplate_config(mode='input', + template='templates/geopoint-input.pt', layer=IFormLayer) @implementer_only(IGeoPointZWidget) class GeoPointZWidget(ObjectWidget): """GeoPointZ widget""" @@ -114,17 +114,25 @@ longitude = widgets['longitude'] longitude.label_css_class = 'control-label col-md-3' longitude.input_css_class = 'col-md-2' - longitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} + longitude.object_data = { + 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' + } alsoProvides(longitude, IObjectData) latitude = widgets['latitude'] latitude.label_css_class = 'control-label col-md-3' latitude.input_css_class = 'col-md-2' - latitude.object_data = {'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate'} + latitude.object_data = { + 'ams-change-handler': 'PyAMS_GIS.position.changedCoordinate' + } alsoProvides(latitude, IObjectData) projection = widgets['projection'] projection.label_css_class = 'control-label col-md-3' latitude.input_css_class = 'col-md-9' - projection.object_data = {'ams-events-handlers': {'change.select2': 'PyAMS_GIS.position.changedProjection'}} + projection.object_data = { + 'ams-events-handlers': { + 'change.select2': 'PyAMS_GIS.position.changedProjection' + } + } alsoProvides(projection, IObjectData) altitude = widgets['altitude'] altitude.label_css_class = 'control-label col-md-3' @@ -134,15 +142,20 @@ def wgs_coordinates(self): value = self.field.get(self.field.interface(self.context)) if not value: - return json.dumps({'longitude': None, - 'latitude': None}) - else: - point = value.wgs_coordinates - return json.dumps({'longitude': float(point[0]), - 'latitude': float(point[1])}) + return json.dumps({ + 'longitude': None, + 'latitude': None + }) + # else: + point = value.wgs_coordinates + return json.dumps({ + 'longitude': float(point[0]), + 'latitude': float(point[1]) + }) -@adapter_config(context=(IGeoPointZField, IFormLayer), provides=IFieldWidget) +@adapter_config(context=(IGeoPointZField, IFormLayer), + provides=IFieldWidget) def GeoPointZFieldWidget(field, request): """GeoPointZ field widget factory""" return FieldWidget(field, GeoPointZWidget(request))