Added checks for "pyams_gis" package availability to enable GPS coordinates attributes
--- a/src/pyams_default_theme/component/paragraph/contact.py Tue Mar 20 17:56:05 2018 +0100
+++ b/src/pyams_default_theme/component/paragraph/contact.py Thu Mar 22 19:13:31 2018 +0100
@@ -17,7 +17,7 @@
from persistent import Persistent
# import interfaces
-from pyams_content.component.paragraph.interfaces.contact import IContactParagraph
+from pyams_content.component.paragraph.interfaces.contact import have_gis, IContactParagraph
from pyams_content.features.renderer.interfaces import IContentRenderer
from pyams_default_theme.component.paragraph.interfaces.contact import IContactParagraphDefaultRendererSettings
from pyams_skin.layer import IPyAMSLayer
@@ -50,13 +50,17 @@
display_map = FieldProperty(IContactParagraphDefaultRendererSettings['display_map'])
map_position = FieldProperty(IContactParagraphDefaultRendererSettings['map_position'])
+ @property
def can_display_photo(self):
contact = IContactParagraph(self.__parent__)
if not contact.photo:
return False
return self.display_photo
+ @property
def can_display_map(self):
+ if not have_gis:
+ return False
contact = IContactParagraph(self.__parent__)
if not contact.gps_location:
return False
@@ -87,5 +91,8 @@
settings_interface = IContactParagraphDefaultRendererSettings
- context_attrs = ('name', 'photo', 'gps_location', 'address')
+ if have_gis:
+ context_attrs = ('name', 'photo', 'gps_location', 'address')
+ else:
+ context_attrs = ('name', 'photo', 'address')
i18n_context_attrs = ('title', 'charge', )
--- a/src/pyams_default_theme/component/paragraph/interfaces/contact.py Tue Mar 20 17:56:05 2018 +0100
+++ b/src/pyams_default_theme/component/paragraph/interfaces/contact.py Thu Mar 22 19:13:31 2018 +0100
@@ -18,7 +18,7 @@
# import interfaces
# import packages
-from zope.interface import Interface
+from zope.interface import Interface, Attribute
from zope.schema import Bool, Choice
from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
@@ -47,8 +47,7 @@
vocabulary=CONTENT_POSITIONS_VOCABULARY,
default='left')
- def can_display_photo(self):
- """Check if photo can be displayed"""
+ can_display_photo = Attribute("Check if photo can be displayed")
display_map = Bool(title=_("Show location map?"),
description=_("If 'no', location map will not be displayed"),
@@ -60,5 +59,4 @@
vocabulary=CONTENT_POSITIONS_VOCABULARY,
default='right')
- def can_display_map(self):
- """Check if location map can be displayed"""
+ can_display_map = Attribute("Check if location map can be displayed")
--- a/src/pyams_default_theme/component/paragraph/templates/contact-default.pt Tue Mar 20 17:56:05 2018 +0100
+++ b/src/pyams_default_theme/component/paragraph/templates/contact-default.pt Thu Mar 22 19:13:31 2018 +0100
@@ -1,11 +1,11 @@
<div class="bordered row contact padding-10"
tal:define="settings view.settings">
<h3 tal:content="view.title">Contact title</h3>
- <div tal:condition="settings.can_display_photo()"
+ <div tal:condition="settings.can_display_photo"
tal:attributes="class string:thumbnail photo pull-${settings.photo_position}">
<img tal:attributes="src extension:absolute_url(view.photo, '++thumb++w128')" />
</div>
- <div tal:condition="settings.can_display_map()"
+ <div tal:condition="settings.can_display_map"
tal:attributes="class string:map pull-${settings.map_position}">
Location map
</div>