Commit 736a0a24 authored by Roque's avatar Roque

erp5_web: romain's fix for web section issues

parent 18c318dc
"""
================================================================================
Proxy of StaticWebSection_getDocumentValue to allow redirection
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
# name main_template
# this script will be cloned into a new one. If the request arrives here, it's because it's using the static web section for hateoas URLs
# so name should be the relative_url (e.g. portal_types/Web%20Page/jio_view)
# that relative_url should be use to call ERP5Document_getHateoas script
# with query: ?mode=traverse&relative_url=portal_types%2FWeb%20Page%2Fjio_view&view=definition_view
# catch KeyError on source_path with urls "", "?", "/?", "...&"
try:
context.REQUEST.other['source_path'] = name
except KeyError:
return context
return context
<?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>name, **kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSection_getDocumentValue</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
"""
================================================================================
Redirect to domain specified as layout property on website
================================================================================
"""
# parameters
# ------------------------------------------------------------------------------
INDEX = "index.html"
REQUEST = context.REQUEST
query_string = REQUEST["QUERY_STRING"]
redirect_domain = context.getLayoutProperty("redirect_domain")
redirect_url = redirect_domain
status_code = 301
if context.getLayoutProperty("use_moved_temporarily"):
status_code = 302
try:
source_path = REQUEST.other["source_path"]
redirect_url = "/".join([redirect_url, source_path])
except(KeyError):
redirect_url = redirect_url + "/"
if query_string:
redirect_url = '?'.join([redirect_url, query_string])
if redirect_url.find(INDEX) > -1 and not redirect_url.endswith(INDEX):
redirect_url = redirect_url.replace(INDEX, '')
if redirect_url.find(INDEX) > -1 and REQUEST['ACTUAL_URL'].find(INDEX) == -1:
redirect_url = redirect_url.replace(INDEX, '')
return context.Base_redirect(redirect_url, status_code=status_code)
<?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>**kw</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>StaticWebSection_getRedirectSourceUrl</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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