Added checks for "pyams_gis" package availability to enable GPS coordinates attributes
authorThierry Florac <tflorac@ulthar.net>
Thu, 22 Mar 2018 19:12:33 +0100
changeset 495 512c874493b9
parent 494 2cb12774d441
child 496 66bae1164f85
Added checks for "pyams_gis" package availability to enable GPS coordinates attributes
src/pyams_content/component/paragraph/contact.py
src/pyams_content/component/paragraph/interfaces/contact.py
--- a/src/pyams_content/component/paragraph/contact.py	Thu Mar 22 15:03:30 2018 +0100
+++ b/src/pyams_content/component/paragraph/contact.py	Thu Mar 22 19:12:33 2018 +0100
@@ -17,7 +17,7 @@
 
 # import interfaces
 from pyams_content.component.paragraph.interfaces import IParagraphFactory
-from pyams_content.component.paragraph.interfaces.contact import IContactParagraph, CONTACT_PARAGRAPH_TYPE, \
+from pyams_content.component.paragraph.interfaces.contact import have_gis, IContactParagraph, CONTACT_PARAGRAPH_TYPE, \
     CONTACT_PARAGRAPH_RENDERERS
 from pyams_content.features.checker.interfaces import IContentChecker, MISSING_VALUE, MISSING_LANG_VALUE
 from pyams_file.interfaces import IImage, IResponsiveImage
@@ -49,7 +49,10 @@
     name = FieldProperty(IContactParagraph['name'])
     charge = FieldProperty(IContactParagraph['charge'])
     _photo = FileProperty(IContactParagraph['photo'])
-    gps_location = FieldProperty(IContactParagraph['gps_location'])
+
+    if have_gis:
+        gps_location = FieldProperty(IContactParagraph['gps_location'])
+
     address = FieldProperty(IContactParagraph['address'])
     renderer = FieldProperty(IContactParagraph['renderer'])
 
@@ -95,7 +98,10 @@
                     output.append(translate(MISSING_VALUE).format(field=field_title))
                 else:
                     output.append(translate(MISSING_LANG_VALUE).format(field=field_title, lang=lang))
-        for attr in ('name', 'photo', 'gps_location', 'address'):
+        attrs = ('name', 'photo', 'address')
+        if have_gis:
+            attrs += ('gps_location', )
+        for attr in attrs:
             value = getattr(self.context, attr, None)
             if not value:
                 field_title = translate(IContactParagraph[attr].title)
--- a/src/pyams_content/component/paragraph/interfaces/contact.py	Thu Mar 22 15:03:30 2018 +0100
+++ b/src/pyams_content/component/paragraph/interfaces/contact.py	Thu Mar 22 19:12:33 2018 +0100
@@ -20,7 +20,12 @@
 
 # import packages
 from pyams_file.schema import ImageField
-from pyams_gis.schema import GeoPointField
+try:
+    from pyams_gis.schema import GeoPointField
+except ImportError:
+    have_gis = False
+else:
+    have_gis = True
 from pyams_i18n.schema import I18nTextLineField
 from zope.schema import TextLine, Text, Choice
 
@@ -50,9 +55,10 @@
                        description=_("Use 'browse' button to select contact picture"),
                        required=False)
 
-    gps_location = GeoPointField(title=_("GPS location"),
-                                 description=_("GPS coordinates used to locate contact"),
-                                 required=False)
+    if have_gis:
+        gps_location = GeoPointField(title=_("GPS location"),
+                                     description=_("GPS coordinates used to locate contact"),
+                                     required=False)
 
     address = Text(title=_("Address"),
                    required=False)