Commit 6910ef67 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

change skin in Web Section if specified, just same as in Web Site.

override _edit() to migrate existing documents if hook is not yet registered.
parent 5dee3616
...@@ -35,6 +35,8 @@ from Acquisition import aq_base, aq_inner ...@@ -35,6 +35,8 @@ from Acquisition import aq_base, aq_inner
from Products.ERP5Type.UnrestrictedMethod import unrestricted_apply from Products.ERP5Type.UnrestrictedMethod import unrestricted_apply
from AccessControl import Unauthorized from AccessControl import Unauthorized
from OFS.Traversable import NotFound from OFS.Traversable import NotFound
from Persistence import Persistent
from ZPublisher import BeforeTraverse
from Products.ERP5Type.Cache import getReadOnlyTransactionCache from Products.ERP5Type.Cache import getReadOnlyTransactionCache
...@@ -42,6 +44,14 @@ from Products.ERP5Type.Cache import getReadOnlyTransactionCache ...@@ -42,6 +44,14 @@ from Products.ERP5Type.Cache import getReadOnlyTransactionCache
WEBSECTION_KEY = 'web_section_value' WEBSECTION_KEY = 'web_section_value'
MARKER = [] MARKER = []
class WebSectionTraversalHook(Persistent):
def __call__(self, container, request):
if not request.get('ignore_layout', None):
# If a skin selection is defined in this web section, change the skin now.
skin_selection_name = container.getSkinSelectionName()
if skin_selection_name and request.get('portal_skin', None) is None:
container.getPortalObject().changeSkin(skin_selection_name)
class WebSection(Domain, DocumentExtensibleTraversableMixin): class WebSection(Domain, DocumentExtensibleTraversableMixin):
""" """
A Web Section is a Domain with an extended API intended to A Web Section is a Domain with an extended API intended to
...@@ -126,6 +136,20 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -126,6 +136,20 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
'404.error.page') '404.error.page')
return document return document
security.declarePrivate( 'manage_beforeDelete' )
def manage_beforeDelete(self, item, container):
if item is self and self.getPortalType() == 'Web Section':
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.unregisterBeforeTraverse(item, handle)
super(WebSection, self).manage_beforeDelete(item, container)
security.declarePrivate( 'manage_afterAdd' )
def manage_afterAdd(self, item, container):
if item is self and self.getPortalType() == 'Web Section':
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.registerBeforeTraverse(item, WebSectionTraversalHook(), handle)
super(WebSection, self).manage_afterAdd(item, container)
security.declareProtected(Permissions.AccessContentsInformation, 'getLayoutProperty') security.declareProtected(Permissions.AccessContentsInformation, 'getLayoutProperty')
def getLayoutProperty(self, key, default=None): def getLayoutProperty(self, key, default=None):
""" """
...@@ -386,3 +410,10 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -386,3 +410,10 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
cache[key] = result cache[key] = result
return result return result
def _edit(self, **kw):
# migrate beforeTraverse hook if missing
if getattr(self, '__before_traverse__', None) is None and self.getPortalType() == 'Web Section':
handle = self.meta_type + '/' + self.getId()
BeforeTraverse.registerBeforeTraverse(self, WebSectionTraversalHook(), handle)
super(WebSection, self)._edit(**kw)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment