[Erp5-report] r20561 - in /experimental/bt5/erp5_xhtml_style_experimental: SkinTemplateItem...
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Apr 16 12:03:49 CEST 2008
Author: mikolaj
Date: Wed Apr 16 12:03:48 2008
New Revision: 20561
URL: http://svn.erp5.org?rev=20561&view=rev
Log:
Helper scripts to be used with new experimental planning box features (r20453) - advanced and automated coloring of boxes + rendering of planning box legend describing the coloring
Added:
experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_getSimulationStateColorText.xml
experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_renderLegendContents.xml
Modified:
experimental/bt5/erp5_xhtml_style_experimental/bt/revision
experimental/bt5/erp5_xhtml_style_experimental/bt/version
Added: experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_getSimulationStateColorText.xml
URL: http://svn.erp5.org/experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_getSimulationStateColorText.xml?rev=20561&view=auto
==============================================================================
--- experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_getSimulationStateColorText.xml (added)
+++ experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_getSimulationStateColorText.xml Wed Apr 16 12:03:48 2008
@@ -1,0 +1,213 @@
+<?xml version="1.0"?>
+<ZopeData>
+ <record id="1" aka="AAAAAAAAAAE=">
+ <pickle>
+ <tuple>
+ <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+ <tuple/>
+ </tuple>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>Python_magic</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>Script_magic</string> </key>
+ <value> <int>3</int> </value>
+ </item>
+ <item>
+ <key> <string>__ac_local_roles__</string> </key>
+ <value>
+ <none/>
+ </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>"""\n
+ This script returns a color value depending on the passed object properties\n
+ Secondly it returns a dictionary describing color mapping to the\n
+ appropriate property values to be used in Legend rendering script.\n
+"""\n
+default_color = \'#D1E8FF\' #used when there\'s no special coloring defined\n
+blank_color = \'#000000\' #used to mark bad color assignment in color dict\n
+box_object_portal_type = box_object.getPortalType()\n
+\n
+# We try to get the appropriate colors dictionary - type based\n
+colors_dict_script_name = \'_\'.join((box_object_portal_type.replace(\' \',\'\'),\'getColorsDict\'))\n
+colors_dict_script = getattr(context, colors_dict_script_name)\n
+if colors_dict_script is None:\n
+ return default_color\n
+colors_dict = colors_dict_script()\n
+\n
+# This function converts recursively mapping lists into \'color_mapping\' dictionaries\n
+# This way it\'s easier to fetch the appropriate values in getColorValueFromDict function\n
+def list2dict(mapping_list):\n
+ mapping_dict = dict(mapping_list)\n
+ for property_value in mapping_dict.keys():\n
+ if hasattr(mapping_dict.get(property_value),\'get\'):\n
+ mapping_dict[property_value][\'color_mapping\'] = list2dict(mapping_dict.get(property_value).get(\'color_mapping\'))\n
+ return mapping_dict\n
+\n
+# Prepare the dictionary\n
+colors_dict[\'color_mapping\'] = list2dict(colors_dict.get(\'color_mapping\'))\n
+\n
+# Retrieve the color text (rgb value) depending on box object properties\n
+def getColorValueFromDict(prepared_dict):\n
+ property_getter_method_name = prepared_dict.get(\'property_getter_method\')\n
+ property_getter_method = getattr(box_object, property_getter_method_name)\n
+ if property_getter_method is None:\n
+ return default_color\n
+ else:\n
+ property_value = property_getter_method()\n
+ mapping_dict = prepared_dict.get(\'color_mapping\')\n
+ if mapping_dict.has_key(property_value):\n
+ if hasattr(mapping_dict.get(property_value),\'get\'):\n
+ return getColorValueFromDict(mapping_dict.get(property_value))\n
+ else:\n
+ return mapping_dict.get(property_value, blank_color)\n
+ elif mapping_dict.has_key(\'rest\'):\n
+ if hasattr(mapping_dict.get(\'rest\'),\'get\'):\n
+ return getColorValueFromDict(mapping_dict.get(\'rest\'))\n
+ else:\n
+ return mapping_dict.get(property_value, blank_color)\n
+ else:\n
+ context.log(\'Undefined coloring for property value: %s, retrieved with property getter: %s\' % (property_value,property_getter_method_name))\n
+ return blank_color\n
+\n
+return getColorValueFromDict(colors_dict)\n
+\n
+# vim: filetype=python\n
+</string> </value>
+ </item>
+ <item>
+ <key> <string>_code</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_filepath</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_owner</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_params</string> </key>
+ <value> <string>box_object=None</string> </value>
+ </item>
+ <item>
+ <key> <string>errors</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ <item>
+ <key> <string>func_code</string> </key>
+ <value>
+ <object>
+ <klass>
+ <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+ </klass>
+ <tuple/>
+ <state>
+ <dictionary>
+ <item>
+ <key> <string>co_argcount</string> </key>
+ <value> <int>1</int> </value>
+ </item>
+ <item>
+ <key> <string>co_varnames</string> </key>
+ <value>
+ <tuple>
+ <string>box_object</string>
+ <string>default_color</string>
+ <string>blank_color</string>
+ <string>_getattr_</string>
+ <string>box_object_portal_type</string>
+ <string>colors_dict_script_name</string>
+ <string>getattr</string>
+ <string>context</string>
+ <string>colors_dict_script</string>
+ <string>None</string>
+ <string>colors_dict</string>
+ <string>list2dict</string>
+ <string>_write_</string>
+ <string>getColorValueFromDict</string>
+ </tuple>
+ </value>
+ </item>
+ </dictionary>
+ </state>
+ </object>
+ </value>
+ </item>
+ <item>
+ <key> <string>func_defaults</string> </key>
+ <value>
+ <tuple>
+ <none/>
+ </tuple>
+ </value>
+ </item>
+ <item>
+ <key> <string>id</string> </key>
+ <value> <string>PlanningBox_getSimulationStateColorText</string> </value>
+ </item>
+ <item>
+ <key> <string>warnings</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+</ZopeData>
Added: experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_renderLegendContents.xml
URL: http://svn.erp5.org/experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_renderLegendContents.xml?rev=20561&view=auto
==============================================================================
--- experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_renderLegendContents.xml (added)
+++ experimental/bt5/erp5_xhtml_style_experimental/SkinTemplateItem/portal_skins/erp5_xhtml_style_experimental/PlanningBox_renderLegendContents.xml Wed Apr 16 12:03:48 2008
@@ -1,0 +1,277 @@
+<?xml version="1.0"?>
+<ZopeData>
+ <record id="1" aka="AAAAAAAAAAE=">
+ <pickle>
+ <tuple>
+ <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+ <tuple/>
+ </tuple>
+ </pickle>
+ <pickle>
+ <dictionary>
+ <item>
+ <key> <string>Python_magic</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>Script_magic</string> </key>
+ <value> <int>3</int> </value>
+ </item>
+ <item>
+ <key> <string>__ac_local_roles__</string> </key>
+ <value>
+ <none/>
+ </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 encoding="cdata"><![CDATA[
+
+"""\n
+ This script returns an html table that should be used\n
+ by the Legend window on the planning box.\n
+ Since it\'s a nice html table it could be used virtually anywhere.\n
+"""\n
+planning_box = context\n
+from Products.ERP5Type.Message import Message\n
+T_ = lambda msg: Message(\'erp5_ui\', msg)\n
+TC_ = lambda msg: Message(\'erp5_content\', msg)\n
+\n
+# Get all possible portal types defined on the planning box\n
+form_id = context.REQUEST.get(\'form_id\')\n
+form = context.restrictedTraverse(form_id)\n
+planning_box = getattr(form,\'planning_box\')\n
+portal_type_list = [portal_type_tuple[0] for portal_type_tuple in planning_box.get_value(\'portal_types\')]\n
+legend_text = ""\n
+\n
+# For each found portal type try to find a type based script with a color dictionary\n
+for portal_type in portal_type_list:\n
+ colors_dict_script_name = \'_\'.join((portal_type.replace(\' \',\'\'),\'getColorsDict\'))\n
+ if hasattr(context, colors_dict_script_name):\n
+ colors_dict_script = getattr(context, colors_dict_script_name)\n
+ else:\n
+ colors_dict_script = None\n
+ if colors_dict_script is None:\n
+ continue\n
+\n
+ # Get the dictionary from the script\n
+ legend_dict = colors_dict_script()\n
+ legend_columns = legend_dict.pop(\'conditions\')\n
+ legend_list = []\n
+\n
+ def composeLegendLine(legend_list, legend_line, dict):\n
+ """\n
+ Recursive function, which descends into the color dictionary\n
+ and returns a list of lists of coloured property titles.\n
+\n
+ eg. [ [\'Leave Request\',\'Vacation\',\'Planned\',\'#ff00ff\']\n
+ [\'Leave Request\',\'Vacation\',\'Confirmed\',\'#00ff00\'] ...\n
+]\n
+ """\n
+ property_getter_method = dict.pop(\'property_getter_method\')\n
+ for item in dict.get(\'color_mapping\'):\n
+ property_value = item[0]\n
+ if hasattr(item[1], \'get\'):\n
+ # item is a key to another dictionary, that means it can be:\n
+ # ... a category\n
+ category = context.portal_categories.resolveCategory(property_value)\n
+ if category is None:\n
+ # ... or an object\n
+ item_value = context.restrictedTraverse(property_value,None)\n
+ if item_value is None:\n
+ # ... or just a text (like a state name)\n
+ if property_value == \'rest\':\n
+ # \'rest\' means all other possible values \n
+ # that are not explicitly included in dictionary\n
+ legend_line.append(T_("Rest"))\n
+ else:\n
+ legend_line.append(T_(property_value))\n
+ else:\n
+ legend_line.append(item_value.getTitle())\n
+ else:\n
+ legend_line.append(TC_(category.getTitle()))\n
+ composeLegendLine(legend_list, legend_line, item[1])\n
+ legend_line.pop()\n
+ else:\n
+ # item is a mapping (key) to specific colour.\n
+ colour = item[1]\n
+ legend_list.append(legend_line + [T_(property_value), colour])\n
+\n
+ composeLegendLine(legend_list, [], legend_dict)\n
+ # Check if list is not empty\n
+ if len(legend_list) == 0:\n
+ return "<div style=\'color: red\' i18n:translate=\'\' i18n:domain=\'ui\'> \\\n
+ Error getting legend entries!</div>"\n
+ # Check if list of columns passed with a dict agrees with columsn in a list\n
+ if len(legend_list[0]) != len(legend_columns):\n
+ return "<div style=\'color: red\' i18n:translate=\'\' i18n:domain=\'ui\'> \\\n
+ Inconsistency in legend description!</div>"\n
+\n
+ legend_text = "<table>"\n
+ for line in legend_list:\n
+ row_html = "<tr>"\n
+ for item in line[:-1]:\n
+ cell_html = "<td width=\'50%%\' align=\'left\'> %s </td>" % item\n
+ row_html += cell_html\n
+ colour_cell_html = "<td bgcolor=%s> </td>" % line[-1]\n
+ row_html += colour_cell_html + "</tr>"\n
+ legend_text += row_html\n
+\n
+if legend_text:\n
+ legend_text += "</table>"\n
+ return legend_text\n
+else:\n
+ return None\n
+\n
+# vim: filetype=python\n
+
+
+]]></string> </value>
+ </item>
+ <item>
+ <key> <string>_code</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_filepath</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_owner</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>_params</string> </key>
+ <value> <string></string> </value>
+ </item>
+ <item>
+ <key> <string>errors</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ <item>
+ <key> <string>func_code</string> </key>
+ <value>
+ <object>
+ <klass>
+ <global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
+ </klass>
+ <tuple/>
+ <state>
+ <dictionary>
+ <item>
+ <key> <string>co_argcount</string> </key>
+ <value> <int>0</int> </value>
+ </item>
+ <item>
+ <key> <string>co_varnames</string> </key>
+ <value>
+ <tuple>
+ <string>context</string>
+ <string>planning_box</string>
+ <string>Products.ERP5Type.Message</string>
+ <string>Message</string>
+ <string>T_</string>
+ <string>TC_</string>
+ <string>_getattr_</string>
+ <string>form_id</string>
+ <string>form</string>
+ <string>getattr</string>
+ <string>append</string>
+ <string>$append0</string>
+ <string>_getiter_</string>
+ <string>portal_type_tuple</string>
+ <string>_getitem_</string>
+ <string>portal_type_list</string>
+ <string>legend_text</string>
+ <string>portal_type</string>
+ <string>colors_dict_script_name</string>
+ <string>hasattr</string>
+ <string>colors_dict_script</string>
+ <string>None</string>
+ <string>legend_dict</string>
+ <string>legend_columns</string>
+ <string>legend_list</string>
+ <string>composeLegendLine</string>
+ <string>len</string>
+ <string>line</string>
+ <string>row_html</string>
+ <string>item</string>
+ <string>cell_html</string>
+ <string>_inplacevar_</string>
+ <string>colour_cell_html</string>
+ </tuple>
+ </value>
+ </item>
+ </dictionary>
+ </state>
+ </object>
+ </value>
+ </item>
+ <item>
+ <key> <string>func_defaults</string> </key>
+ <value>
+ <none/>
+ </value>
+ </item>
+ <item>
+ <key> <string>id</string> </key>
+ <value> <string>PlanningBox_renderLegendContents</string> </value>
+ </item>
+ <item>
+ <key> <string>warnings</string> </key>
+ <value>
+ <tuple/>
+ </value>
+ </item>
+ </dictionary>
+ </pickle>
+ </record>
+</ZopeData>
Modified: experimental/bt5/erp5_xhtml_style_experimental/bt/revision
URL: http://svn.erp5.org/experimental/bt5/erp5_xhtml_style_experimental/bt/revision?rev=20561&r1=20560&r2=20561&view=diff
==============================================================================
--- experimental/bt5/erp5_xhtml_style_experimental/bt/revision (original)
+++ experimental/bt5/erp5_xhtml_style_experimental/bt/revision Wed Apr 16 12:03:48 2008
@@ -1,1 +1,1 @@
-22
+23
Modified: experimental/bt5/erp5_xhtml_style_experimental/bt/version
URL: http://svn.erp5.org/experimental/bt5/erp5_xhtml_style_experimental/bt/version?rev=20561&r1=20560&r2=20561&view=diff
==============================================================================
--- experimental/bt5/erp5_xhtml_style_experimental/bt/version (original)
+++ experimental/bt5/erp5_xhtml_style_experimental/bt/version Wed Apr 16 12:03:48 2008
@@ -1,1 +1,1 @@
-0.2.1
+0.2.2
More information about the Erp5-report
mailing list