src/pyams_content/features/menu/portlet/navigation/double.py
changeset 689 029787887199
child 691 773429b4a3ed
equal deleted inserted replaced
688:22a501f58d06 689:029787887199
       
     1 #
       
     2 # Copyright (c) 2008-2018 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 
       
    18 # import interfaces
       
    19 from pyams_content.component.association.interfaces import ASSOCIATION_CONTAINER_KEY
       
    20 from pyams_content.component.illustration.interfaces import IBasicIllustrationTarget
       
    21 from pyams_content.features.menu.interfaces import IMenusContainer, IMenusContainerTarget
       
    22 from pyams_content.features.menu.portlet.navigation.interfaces.double import IDoubleNavigationPortletSettings, \
       
    23     IDoubleNavigationMenu, IDoubleNavigationMenusContainer
       
    24 from pyams_utils.interfaces import VIEW_PERMISSION
       
    25 from zope.lifecycleevent.interfaces import IObjectAddedEvent
       
    26 
       
    27 # import packages
       
    28 from pyams_content.features.menu import MenusContainer
       
    29 from pyams_portal.portlet import PortletSettings, portlet_config, Portlet
       
    30 from pyams_utils.adapter import get_annotation_adapter, adapter_config
       
    31 from pyramid.events import subscriber
       
    32 from zope.interface import implementer, alsoProvides
       
    33 from zope.schema.fieldproperty import FieldProperty
       
    34 
       
    35 from pyams_content import _
       
    36 
       
    37 
       
    38 DOUBLE_NAVIGATION_PORTLET_NAME = 'pyams_content.portlet.navigation.double'
       
    39 DOUBLE_NAVIGATION_LINKS_KEY = '{0}::menus'.format(ASSOCIATION_CONTAINER_KEY)
       
    40 
       
    41 
       
    42 @implementer(IDoubleNavigationPortletSettings, IMenusContainerTarget)
       
    43 class DoubleNavigationPortletSettings(PortletSettings):
       
    44     """Double navigation portlet settings"""
       
    45 
       
    46     title = FieldProperty(IDoubleNavigationPortletSettings['title'])
       
    47     subtitle = FieldProperty(IDoubleNavigationPortletSettings['subtitle'])
       
    48 
       
    49     @property
       
    50     def menus(self):
       
    51         return get_annotation_adapter(self, DOUBLE_NAVIGATION_LINKS_KEY, MenusContainer,
       
    52                                       markers=IDoubleNavigationMenusContainer, name='++ass++menus')
       
    53 
       
    54 
       
    55 @adapter_config(name='menus', context=IDoubleNavigationPortletSettings, provides=IMenusContainer)
       
    56 def simple_navigation_links_adapter(context):
       
    57     """Double navigation menus factory"""
       
    58     return context.menus
       
    59 
       
    60 
       
    61 @portlet_config(permission=VIEW_PERMISSION)
       
    62 class DoubleNavigationPortlet(Portlet):
       
    63     """Double navigation portlet"""
       
    64 
       
    65     name = DOUBLE_NAVIGATION_PORTLET_NAME
       
    66     label = _("Double navigation")
       
    67 
       
    68     settings_class = DoubleNavigationPortletSettings
       
    69 
       
    70 
       
    71 @subscriber(IObjectAddedEvent, parent_selector=IDoubleNavigationMenusContainer)
       
    72 def handle_added_navigation_menu(event):
       
    73     """Add marker interface to added menus container"""
       
    74     alsoProvides(event.object, IDoubleNavigationMenu, IBasicIllustrationTarget)
       
    75 
       
    76 
       
    77 @subscriber(IObjectAddedEvent, parent_selector=IDoubleNavigationMenu)
       
    78 def handle_added_navigation_menu_link(event):
       
    79     """Add marker interface to added menu link"""
       
    80     alsoProvides(event.object, IBasicIllustrationTarget)