Commit 61c39f48 authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web&erp5_web_ui_test: do redirect when portal_skin is present

If ignore_layout=1 is present in url query, static web section show the default view so user can modify properties

But for url like
https://erp5/web_site_module/static_web_site/web_page_module/111?ignore_layout:int=1&portal_skin=Slide...
static web section should do redirection instead of showing the default view

It's difficult to distinguish if it should do redirection or show the
default view for all kinds of url

To make it simple, if portal_skin is present in url query, static web
section will do redirection event if ignore_layout is present
parent 3379bd22
......@@ -102,6 +102,8 @@ class StaticWebSection(WebSection):
except AttributeError:
raise KeyError(name)
def _checkIfRenderDefaultDocument(self):
return self.REQUEST.get('portal_skin', None) or super(StaticWebSection, self)._checkIfRenderDefaultDocument()
security.declareProtected(Permissions.View, '__bobo_traverse__')
def __bobo_traverse__(self, request, name):
......
......@@ -189,6 +189,9 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
"""
return self
def _checkIfRenderDefaultDocument(self):
return not self.REQUEST.get('editable_mode') and not self.REQUEST.get('ignore_layout')
# Default view display
security.declareProtected(Permissions.View, '__call__')
def __call__(self):
......@@ -217,7 +220,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
if self.REQUEST.get(self.web_section_key, MARKER) is MARKER:
self.REQUEST[self.web_section_key] = self.getPhysicalPath()
self.REQUEST.set('current_web_section', self)
if not self.REQUEST.get('editable_mode') and not self.REQUEST.get('ignore_layout'):
if self._checkIfRenderDefaultDocument():
document = None
if self.isDefaultPageDisplayed():
# The following could be moved to a typed based method for more flexibility
......@@ -450,4 +453,4 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
else:
# cleanup beforeTraverse hooks that may exist after this document was cloned.
self._cleanupBeforeTraverseHooks()
super(WebSection, self)._edit(**kw)
\ No newline at end of file
super(WebSection, self)._edit(**kw)
# Don't keep any parameters when do redirect.
# This prevent duplicated parameter in redirect_url which contains already all parameters
return dict()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>parameter_list</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_filterParameterList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -176,6 +176,12 @@ class TestStaticWebSiteRedirection(ERP5TypeTestCase):
def test_queryStringPortalSkin(self):
self.runTestRedirect("?portal_skin=FOOBAR")
def test_queryStringIgnoreLayoutWithQueryStringPortalSkin(self):
self.runTestRedirect("?portal_skin=FOOBAR&ignore_layout=1")
def test_queryStringEditableModeWithQueryStringPortalSkin(self):
self.runTestRedirect("?portal_skin=FOOBAR&editable_mode=1")
def test_plainRedirectGetId(self):
self.runTestRedirect("getId")
......
......@@ -40,10 +40,10 @@ class WebSectionTraversalHook(Persistent):
"""Traversal hook to change the skin selection for this websection.
"""
def __call__(self, container, request):
if not request.get('ignore_layout', None):
portal_skin = request.get('portal_skin', None)
if (not request.get('ignore_layout', None) and portal_skin is None) or \
(container.getPortalType() not in WEB_SECTION_PORTAL_TYPE_TUPLE and portal_skin):
# 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) or \
container.getPortalType() not in WEB_SECTION_PORTAL_TYPE_TUPLE):
container.getPortalObject().changeSkin(skin_selection_name)
if skin_selection_name:
container.getPortalObject().changeSkin(skin_selection_name)
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