src/pyams_gis/zmi/widget/point.py
changeset 74 31687784fa16
parent 68 b0a03a00c83e
--- 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))