Mixed adapters to IContentNavigationIllustration into a single one
authorThierry Florac <thierry.florac@onf.fr>
Thu, 27 Sep 2018 15:51:18 +0200
changeset 155 85788af89ed5
parent 154 1972dd25e1d2
child 156 ddf8cc5bca45
Mixed adapters to IContentNavigationIllustration into a single one
src/pyams_default_theme/features/menu/__init__.py
src/pyams_default_theme/shared/common/__init__.py
--- a/src/pyams_default_theme/features/menu/__init__.py	Tue Sep 25 11:37:34 2018 +0200
+++ b/src/pyams_default_theme/features/menu/__init__.py	Thu Sep 27 15:51:18 2018 +0200
@@ -11,28 +11,3 @@
 #
 
 __docformat__ = 'restructuredtext'
-
-
-# import standard library
-
-# import interfaces
-from pyams_content.component.illustration import IBasicIllustration
-from pyams_content.component.links.interfaces import IBaseLink, IInternalLink
-from pyams_default_theme.interfaces import IContentNavigationIllustration
-from pyams_skin.layer import IPyAMSLayer
-
-# import packages
-from pyams_utils.adapter import adapter_config
-
-
-@adapter_config(context=(IBaseLink, IPyAMSLayer), provides=IContentNavigationIllustration)
-def base_link_navigation_illustration_adapter(context, request):
-    """Base link navigation illustration adapter"""
-    illustration = IBasicIllustration(context, None)
-    if not (illustration and illustration.has_data()):
-        if IInternalLink.providedBy(context):
-            target = context.get_target()
-            if target is not None:
-                illustration = request.registry.queryMultiAdapter((target, request),
-                                                                  IContentNavigationIllustration)
-    return illustration
--- a/src/pyams_default_theme/shared/common/__init__.py	Tue Sep 25 11:37:34 2018 +0200
+++ b/src/pyams_default_theme/shared/common/__init__.py	Thu Sep 27 15:51:18 2018 +0200
@@ -10,27 +10,24 @@
 # FOR A PARTICULAR PURPOSE.
 #
 
+
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
+from zope.interface import Interface
 
-# import interfaces
-from pyams_content.component.illustration import ILinkIllustration, IIllustration, IBasicIllustrationTarget
+from pyams_content.component.illustration import IBasicIllustrationTarget, IIllustration, ILinkIllustration
+from pyams_content.component.links import IInternalLink
 from pyams_content.interfaces import IBaseContent
 from pyams_content.shared.common.interfaces import IWfSharedContent
-from pyams_default_theme.interfaces import IContentNavigationTitle, IContentTag, IContentDate, \
-    IContentNavigationIllustration
+from pyams_default_theme.interfaces import IContentDate, IContentNavigationIllustration, IContentNavigationTitle, \
+    IContentTag
 from pyams_i18n.interfaces import II18n
 from pyams_skin.layer import IPyAMSLayer
+from pyams_utils.adapter import ContextRequestViewAdapter, adapter_config
+from pyams_utils.date import SH_DATE_FORMAT, format_date
 from pyams_utils.interfaces.tales import ITALESExtension
 from pyams_workflow.interfaces import IWorkflowPublicationInfo
 
-# import packages
-from pyams_utils.adapter import adapter_config, ContextRequestViewAdapter
-from pyams_utils.date import format_date, SH_DATE_FORMAT
-from zope.interface import Interface
-
 
 @adapter_config(context=(IBaseContent, IPyAMSLayer), provides=IContentNavigationTitle)
 def shared_content_navigation_title(context, request):
@@ -90,7 +87,6 @@
         return self.request.registry.queryMultiAdapter((context, self.request), IContentDate)
 
 
-@adapter_config(context=(IBaseContent, IPyAMSLayer), provides=IContentNavigationIllustration)
 @adapter_config(context=(IBasicIllustrationTarget, IPyAMSLayer), provides=IContentNavigationIllustration)
 def base_content_navigation_illustration_adapter(context, request):
     """Default content navigation illustration adapter"""
@@ -99,6 +95,13 @@
         illustration = IIllustration(context, None)
     if illustration and illustration.has_data():
         return illustration
+    if IInternalLink.providedBy(context):
+        target = context.get_target()
+        if target is not None:
+            illustration = request.registry.queryMultiAdapter((target, request),
+                                                              IContentNavigationIllustration)
+            if illustration and illustration.has_data():
+                return illustration
 
 
 @adapter_config(name='pyams_illustration',