From 2fce628b779904a3b4bf51dcdd41ea5428d0c531 Mon Sep 17 00:00:00 2001
From: Vincent Pelletier <vincent@nexedi.com>
Date: Mon, 6 Aug 2007 17:22:11 +0000
Subject: [PATCH] Make Base_getFieldDescription design more
 object-oriented-ish. Rename Base_getFieldDescription into
 Field_getDescription. Update callers.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15502 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 ...scription.xml => Field_getDescription.xml} | 53 ++++++++++++-------
 .../erp5_xhtml_style/field_render.xml         |  2 +-
 .../erp5_xhtml_style/form_dialog.xml          |  2 +-
 .../bootstrap/erp5_xhtml_style/bt/revision    |  2 +-
 4 files changed, 37 insertions(+), 22 deletions(-)
 rename product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/{Base_getFieldDescription.xml => Field_getDescription.xml} (78%)

diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_getFieldDescription.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Field_getDescription.xml
similarity index 78%
rename from product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_getFieldDescription.xml
rename to product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Field_getDescription.xml
index a26dc12442..8922c5af1e 100644
--- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Base_getFieldDescription.xml
+++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/Field_getDescription.xml
@@ -70,26 +70,36 @@
             <key> <string>_body</string> </key>
             <value> <string>from Products.ERP5Type.Cache import CachingMethod\n
 \n
+field = context\n
 field_id = field.getId()\n
+form = field.aq_parent\n
+form_id = form.getId()\n
+document = form.aq_parent\n
+if getattr(document, \'getPortalType\', None) is None:\n
+  document = None\n
 \n
-def getFieldDescription():\n
+def getFieldDescription(field_id):\n
   desc = field.get_value(\'description\')\n
   if desc in (\'\', None):\n
-    id = field_id.split(\'_\', 1)\n
-    if id[0] == \'my\':\n
-      try:\n
-        properties = context.propertyMap()\n
-      except AttributeError: # If context has no propertyMap, give up\n
-        properties = []\n
-      for property in properties:\n
-        if id[1] == property[\'id\']:\n
-          return property.get(\'description\', \'\')\n
+    split_id = field_id.split(\'_\', 1)\n
+    if split_id[0] == \'my\':\n
+      if document is None:\n
+        desc = \'Dummy field description for %s\' % (field_id, )\n
+      else:\n
+        try:\n
+          properties = document.propertyMap()\n
+        except AttributeError: # If context has no propertyMap, give up\n
+          properties = []\n
+        for property in properties:\n
+          if split_id[1] == property[\'id\']:\n
+            desc = property.get(\'description\', \'\')\n
+            break\n
   return desc\n
 \n
-getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id, field_id), \\\n
-                                    cache_factory=\'erp5_ui_long\')\n
-\n
-return getFieldDescription()\n
+if document is not None:\n
+  getFieldDescription = CachingMethod(getFieldDescription, (\'getFieldDescription\', form_id), \\\n
+                                      cache_factory=\'erp5_ui_long\')\n
+return getFieldDescription(field_id)\n
 </string> </value>
         </item>
         <item>
@@ -112,7 +122,7 @@ return getFieldDescription()\n
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>form_id, field</string> </value>
+            <value> <string></string> </value>
         </item>
         <item>
             <key> <string>errors</string> </key>
@@ -132,18 +142,23 @@ return getFieldDescription()\n
                   <dictionary>
                     <item>
                         <key> <string>co_argcount</string> </key>
-                        <value> <int>2</int> </value>
+                        <value> <int>0</int> </value>
                     </item>
                     <item>
                         <key> <string>co_varnames</string> </key>
                         <value>
                           <tuple>
-                            <string>form_id</string>
-                            <string>field</string>
                             <string>Products.ERP5Type.Cache</string>
                             <string>CachingMethod</string>
+                            <string>context</string>
+                            <string>field</string>
                             <string>_getattr_</string>
                             <string>field_id</string>
+                            <string>form</string>
+                            <string>form_id</string>
+                            <string>document</string>
+                            <string>getattr</string>
+                            <string>None</string>
                             <string>getFieldDescription</string>
                           </tuple>
                         </value>
@@ -161,7 +176,7 @@ return getFieldDescription()\n
         </item>
         <item>
             <key> <string>id</string> </key>
-            <value> <string>Base_getFieldDescription</string> </value>
+            <value> <string>Field_getDescription</string> </value>
         </item>
         <item>
             <key> <string>warnings</string> </key>
diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/field_render.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/field_render.xml
index 257b38a37d..e7d98afd4b 100644
--- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/field_render.xml
+++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/field_render.xml
@@ -85,7 +85,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n
                          field_errors python: request.get(\'field_errors\', {});\n
                          field_has_error  python: field_errors.has_key(field_id);\n
                          global form_id form_id | python: form.id;\n
-                         field_description python: here.Base_getFieldDescription(form_id=form_id, field=field);\n
+                         field_description field/Field_getDescription;\n
                          is_web_mode is_web_mode | nothing">\n
     <div tal:define="html_render  python: field.render_htmlgrid(value, request)"\n
          tal:attributes="title field_description;\n
diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/form_dialog.xml b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/form_dialog.xml
index ebf81c871c..ff061a437d 100644
--- a/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/form_dialog.xml
+++ b/product/ERP5/bootstrap/erp5_xhtml_style/SkinTemplateItem/portal_skins/erp5_xhtml_style/form_dialog.xml
@@ -150,7 +150,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n
             <tal:block tal:condition="preferred_html_style_developper_mode">\n
               <tal:block metal:use-macro="developper_shortcut_render/macros/field_developper"/>\n
             </tal:block>\n
-            <tal:block tal:define="field_description python: here.Base_getFieldDescription(form_id=form.id, field=field)"\n
+            <tal:block tal:define="field_description field/Field_getDescription"\n
                        tal:condition="preferred_html_style_translator_mode">\n
               <tal:block metal:use-macro="developper_shortcut_render/macros/field_translator"/>\n
             </tal:block>\n
diff --git a/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision b/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision
index 009bd2c17f..92c732d008 100644
--- a/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision
+++ b/product/ERP5/bootstrap/erp5_xhtml_style/bt/revision
@@ -1 +1 @@
-407
\ No newline at end of file
+408
-- 
2.30.9