Commit 4feb8f4d authored by Gabriel Monnerat's avatar Gabriel Monnerat

Refactor code to remove code duplicated related to get real context. Also, the...

Refactor code to remove code duplicated related to get real context. Also, the language is removed if exists and the context is a Web Section or Web Site
parent 1db1610e
<?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>_body</string> </key>
<value> <string>real_context = context\n
if real_context.isTempObject():\n
real_context = real_context.getParentValue()\n
\n
web_site_value = real_context.getWebSiteValue()\n
if web_site_value is not None and web_site_value.isTempObject():\n
real_web_site_value = web_site_value.getParentValue()\n
while real_web_site_value.isTempObject():\n
real_web_site_value = real_web_site_value.getParentValue()\n
web_site_url = web_site_value.getRelativeUrl()\n
web_site_url_without_language = real_web_site_value.getRelativeUrl()\n
real_context_url = real_context.getRelativeUrl()\n
real_context_url_without_language = real_context_url.replace(web_site_url, web_site_url_without_language, 1)\n
real_context = context.getPortalObject().restrictedTraverse(real_context_url_without_language)\n
\n
return real_context\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getRealContext</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -55,9 +55,7 @@
# for web mode\n
if mode in (\'web_front\', \'web_section\',):\n
# in Web Mode we can have a temporary Web Site objects created based on current language\n
real_context = context\n
if context.isTempObject():\n
real_context = context.getParentValue()\n
real_context = context.Base_getRealContext()\n
pad.setPublicationSectionValue(real_context)\n
\n
# set it as active\n
......
......@@ -102,9 +102,7 @@ if knowledge_pad is None:\n
activate_kw = activate_kw)\n
if is_web_mode:\n
# in Web Mode we can have a temporary Web Site objects created based on current language\n
real_context = context\n
if context.isTempObject():\n
real_context = context.getParentValue()\n
real_context = context.Base_getRealContext()\n
if real_context.getPortalType() == \'Web Site\' and default_pad_group in (\'\', None,):\n
# script is called within Front Page Gadgets view\n
knowledge_pad.setPublicationSectionValue(real_context)\n
......
......@@ -69,17 +69,9 @@ active_knowledge_pad, knowledge_pads = \\\n
if active_knowledge_pad is not None:\n
return active_knowledge_pad, knowledge_pads\n
\n
# in Web Mode we can have a temporary object created based on current language, document by reference\n
real_context = context\n
while real_context.isTempObject():\n
real_context = real_context.getParentValue()\n
real_context = context.Base_getRealContext()\n
real_context_url = real_context.getRelativeUrl()\n
\n
real_context_url_list = real_context_url.split("/")\n
current_language = context.Localizer.get_selected_language()\n
if current_language in real_context_url_list:\n
real_context_url = "/".join(filter(lambda x: x != current_language, real_context_url_list))\n
\n
# first filter if we have a custom Pad for the context\n
for knowledge_pad in knowledge_pads:\n
pad_state = knowledge_pad.getValidationState()\n
......
......@@ -58,11 +58,8 @@ from zExceptions import Unauthorized\n
def filterKnowledgePadListForContext(results, mode, \n
default_pad_group):\n
# in Web Mode we can have a temporary object created based on current language, document by reference\n
real_context = context\n
while real_context.isTempObject():\n
real_context = real_context.getParentValue()\n
real_context = context.Base_getRealContext()\n
real_context_url = real_context.getRelativeUrl()\n
\n
if mode == \'erp5_front\':\n
# leave only those not having a publication_section as \n
# this means belonging to root\n
......
757
\ No newline at end of file
758
\ No newline at end of file
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