Commit c1d59cab authored by Ivan Tyagov's avatar Ivan Tyagov

Make it possible to control breadcrumb string shortening through Web Site configuration.

Clean up scripts and add needed configuration ERP5 form field.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36088 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ad8e530a
...@@ -68,7 +68,6 @@ ...@@ -68,7 +68,6 @@
\n \n
XXX: move this script as an API of ERP5Type?\n XXX: move this script as an API of ERP5Type?\n
"""\n """\n
\n
return context.getProperty(\'translated_short_title\', None) or \\\n return context.getProperty(\'translated_short_title\', None) or \\\n
context.getProperty(\'short_title\', None) or \\\n context.getProperty(\'short_title\', None) or \\\n
context.getProperty(\'translated_title_or_id\', None) or \\\n context.getProperty(\'translated_title_or_id\', None) or \\\n
......
...@@ -53,7 +53,9 @@ ...@@ -53,7 +53,9 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>"""\n <value> <string encoding="cdata"><![CDATA[
"""\n
This script is part of ERP5 Web\n This script is part of ERP5 Web\n
\n \n
ERP5 Web is a business template of ERP5 which provides a way\n ERP5 Web is a business template of ERP5 which provides a way\n
...@@ -112,24 +114,44 @@ if document is None: document = context\n ...@@ -112,24 +114,44 @@ if document is None: document = context\n
crumb_list = []\n crumb_list = []\n
\n \n
# Implementation consists in browsing the aq_parent sequence\n # Implementation consists in browsing the aq_parent sequence\n
web_site = context.getWebSiteValue()\n
chain_list = document.Base_getAcquisitionParentValueList(upper_portal_type=\'Web Site\')\n chain_list = document.Base_getAcquisitionParentValueList(upper_portal_type=\'Web Site\')\n
chain_list.reverse()\n chain_list.reverse()\n
for i in xrange(0, len(chain_list)):\n \n
last_breadcrumb_offset = 1\n
max_breadcrumb_length = web_site.getLayoutProperty(\'layout_max_breadcrumb_length\', None)\n
chain_list_length = len(chain_list)\n
\n
is_web_section_default_document = bool(context.REQUEST.get(\'is_web_section_default_document\', False))\n
if is_web_section_default_document:\n
last_breadcrumb_offset = 2\n
\n
for chain_index in xrange(0, chain_list_length):\n
try:\n try:\n
crumb = chain_list[i]\n crumb = chain_list[chain_index]\n
if i == 0:\n if chain_index == 0:\n
title = context.Base_translateString(\'Home\')\n title = context.Base_translateString(\'Home\')\n
else:\n else:\n
title = crumb.Base_getTitle()\n title = crumb.Base_getTitle()\n
crumb_list.append((title, crumb))\n
except Unauthorized:\n except Unauthorized:\n
# We should ignore any item in the chain which raises \n # We should ignore any item in the chain which raises \n
# a security exception. We use a catchall except here\n # a security exception. We use a catchall except here\n
# because there is no way to import Unauthorized permission\n # because there is no way to import Unauthorized permission\n
pass\n title = None\n
\n
if title is not None:\n
# shorten it only if it exceeds maximum specified length or\n
# not last element in breadcrumb (include default Web Page which is not show but part of chain_list)\n
if max_breadcrumb_length is not None and \\\n
(chain_index + last_breadcrumb_offset < chain_list_length) and \\\n
(len(title) - 4 > max_breadcrumb_length):\n
title = \'%s ...\' %(title[:max_breadcrumb_length])\n
crumb_list.append((title, crumb))\n
\n \n
return crumb_list\n return crumb_list\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_code</string> </key> <key> <string>_code</string> </key>
...@@ -178,11 +200,18 @@ return crumb_list\n ...@@ -178,11 +200,18 @@ return crumb_list\n
<string>context</string> <string>context</string>
<string>crumb_list</string> <string>crumb_list</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>web_site</string>
<string>chain_list</string> <string>chain_list</string>
<string>last_breadcrumb_offset</string>
<string>max_breadcrumb_length</string>
<string>len</string>
<string>chain_list_length</string>
<string>bool</string>
<string>False</string>
<string>is_web_section_default_document</string>
<string>_getiter_</string> <string>_getiter_</string>
<string>xrange</string> <string>xrange</string>
<string>len</string> <string>chain_index</string>
<string>i</string>
<string>_getitem_</string> <string>_getitem_</string>
<string>crumb</string> <string>crumb</string>
<string>title</string> <string>title</string>
......
...@@ -107,6 +107,7 @@ ...@@ -107,6 +107,7 @@
<string>my_layout_widget_legend_background</string> <string>my_layout_widget_legend_background</string>
<string>my_layout_widget_legend_color</string> <string>my_layout_widget_legend_color</string>
<string>my_layout_widget_border_color</string> <string>my_layout_widget_border_color</string>
<string>my_layout_max_breadcrumb_length</string>
</list> </list>
</value> </value>
</item> </item>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>delegated_list</string> </key>
<value>
<list>
<string>title</string>
</list>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>my_layout_max_breadcrumb_length</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_integer_field</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Base_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Maximal Breadcrumb Item Length</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
957 959
\ No newline at end of file \ 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