src/pyams_default_theme/component/paragraph/contact.py
changeset 9 e81e39878694
child 20 bdd0b79668a1
equal deleted inserted replaced
8:3968b35afde8 9:e81e39878694
       
     1 #
       
     2 # Copyright (c) 2008-2017 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 from persistent import Persistent
       
    18 
       
    19 # import interfaces
       
    20 from pyams_content.component.paragraph.interfaces.contact import IContactParagraph
       
    21 from pyams_content.features.renderer.interfaces import IContentRenderer
       
    22 from pyams_default_theme.component.paragraph.interfaces.contact import IContactParagraphDefaultRendererSettings
       
    23 from pyams_skin.layer import IPyAMSLayer
       
    24 from zope.annotation.interfaces import IAnnotations
       
    25 
       
    26 # import packages
       
    27 from pyams_content.features.renderer.zmi import BaseContentRenderer
       
    28 from pyams_template.template import template_config
       
    29 from pyams_utils.adapter import adapter_config
       
    30 from zope.interface import implementer
       
    31 from zope.location import locate, Location
       
    32 from zope.schema.fieldproperty import FieldProperty
       
    33 
       
    34 from pyams_default_theme import _
       
    35 
       
    36 
       
    37 #
       
    38 # Contact paragraph default renderer settings
       
    39 #
       
    40 
       
    41 CONTACT_DEFAULT_RENDERER_SETTINGS_KEY = 'pyams_content.contact.renderer:default'
       
    42 
       
    43 
       
    44 @implementer(IContactParagraphDefaultRendererSettings)
       
    45 class ContactParagraphDefaultRendererSettings(Persistent, Location):
       
    46     """Contact paragraph default renderer settings"""
       
    47 
       
    48     display_photo = FieldProperty(IContactParagraphDefaultRendererSettings['display_photo'])
       
    49     photo_position = FieldProperty(IContactParagraphDefaultRendererSettings['photo_position'])
       
    50     display_map = FieldProperty(IContactParagraphDefaultRendererSettings['display_map'])
       
    51     map_position = FieldProperty(IContactParagraphDefaultRendererSettings['map_position'])
       
    52 
       
    53     def can_display_photo(self):
       
    54         contact = IContactParagraph(self.__parent__)
       
    55         if not contact.photo:
       
    56             return False
       
    57         return self.display_photo
       
    58 
       
    59     def can_display_map(self):
       
    60         contact = IContactParagraph(self.__parent__)
       
    61         if not contact.gps_location:
       
    62             return False
       
    63         return self.display_map
       
    64 
       
    65 
       
    66 @adapter_config(context=IContactParagraph, provides=IContactParagraphDefaultRendererSettings)
       
    67 def ContactParagraphDefaultRendererSettingsFactory(context):
       
    68     """Contact paragraph default renderer settings factory"""
       
    69     annotations = IAnnotations(context)
       
    70     settings = annotations.get(CONTACT_DEFAULT_RENDERER_SETTINGS_KEY)
       
    71     if settings is None:
       
    72         settings = annotations[CONTACT_DEFAULT_RENDERER_SETTINGS_KEY] = ContactParagraphDefaultRendererSettings()
       
    73         locate(settings, context)
       
    74     return settings
       
    75 
       
    76 
       
    77 #
       
    78 # Contact paragraph default renderer
       
    79 #
       
    80 
       
    81 @adapter_config(name='default', context=(IContactParagraph, IPyAMSLayer), provides=IContentRenderer)
       
    82 @template_config(template='templates/contact-default.pt', layer=IPyAMSLayer)
       
    83 class ContactParagraphDefaultRenderer(BaseContentRenderer):
       
    84     """Context paragraph default renderer"""
       
    85 
       
    86     label = _("Default contact renderer")
       
    87 
       
    88     settings_interface = IContactParagraphDefaultRendererSettings
       
    89 
       
    90     context_attrs = ('name', 'photo', 'gps_location', 'address')
       
    91     i18n_context_attrs = ('title', 'charge', )