Check display context to display header when shared content is displayed in site root's context
authorThierry Florac <tflorac@ulthar.net>
Sun, 13 Jan 2019 10:09:59 +0100
changeset 370 9a5f4a56e3ac
parent 369 bb30d6a57ffb
child 371 9b310350d394
Check display context to display header when shared content is displayed in site root's context
src/pyams_default_theme/features/header/skin/__init__.py
src/pyams_default_theme/routes.py
--- a/src/pyams_default_theme/features/header/skin/__init__.py	Sat Jan 12 18:35:55 2019 +0100
+++ b/src/pyams_default_theme/features/header/skin/__init__.py	Sun Jan 13 10:09:59 2019 +0100
@@ -24,6 +24,7 @@
     IHeaderTarget
 from pyams_content.features.renderer.interfaces import HIDDEN_RENDERER_NAME
 from pyams_content.root import ISiteRoot
+from pyams_default_theme import _
 from pyams_default_theme.features.header import SimpleHeaderRendererSettings
 from pyams_default_theme.features.header.interfaces import ISimpleHeaderRendererSettings
 from pyams_default_theme.features.header.skin.interfaces import IHeaderClass
@@ -36,9 +37,9 @@
 from pyams_template.template import template_config
 from pyams_utils.adapter import adapter_config
 from pyams_utils.interfaces import ICacheKeyValue
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
 from pyams_utils.traversing import get_parent
 
-from pyams_default_theme import _
 
 logger = logging.getLogger('PyAMS (content)')
 
@@ -88,8 +89,12 @@
         return get_reference_target(self.settings.search_target, request=self.request)
 
     def render(self):
-        if ISiteRoot.providedBy(self.request.context) and not self.settings.can_apply_on_root:
+        # root condition applies only when not displaying a shared content
+        if ISiteRoot.providedBy(self.request.context) and \
+                (self.request.annotations.get(DISPLAY_CONTEXT) is None) and \
+                not self.settings.can_apply_on_root:
             return ''
+        # don't use cache in preview mode
         preview_mode = self.request.annotations.get(PREVIEW_MODE, False)
         if preview_mode:
             return super(BaseHeaderRenderer, self).render()
--- a/src/pyams_default_theme/routes.py	Sat Jan 12 18:35:55 2019 +0100
+++ b/src/pyams_default_theme/routes.py	Sun Jan 13 10:09:59 2019 +0100
@@ -18,6 +18,7 @@
 
 from pyams_sequence.interfaces import ISequentialIntIds
 from pyams_sequence.reference import get_reference_target
+from pyams_utils.interfaces.url import DISPLAY_CONTEXT
 from pyams_utils.registry import get_utility
 from pyams_utils.url import absolute_url, canonical_url
 from pyams_workflow.interfaces import IWorkflow, IWorkflowPublicationInfo, IWorkflowVersions
@@ -55,6 +56,7 @@
                 location = canonical_url(target, request)
             if location == request.url:
                 # return view response to avoid infinite redirection!
+                request.annotations[DISPLAY_CONTEXT] = request.context
                 response = render_view_to_response(target, request, view_name)
             else:
                 response = Response()