From f985655d301f79fadbe982eda8387352bccbb6b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Wed, 13 Mar 2013 17:42:44 +0100
Subject: [PATCH] content_translation: introspect portal types to catalog all
 content translation properties

It's no longer needed to configure using the script
---
 ...alogTool_getContentTranslationDictList.xml | 17 ++--
 ...getPortalTypeContentTranslationMapping.xml | 88 +++++++++++++++++++
 bt5/erp5_content_translation/bt/revision      |  2 +-
 3 files changed, 95 insertions(+), 12 deletions(-)
 create mode 100644 bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/ERP5Site_getPortalTypeContentTranslationMapping.xml

diff --git a/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/CatalogTool_getContentTranslationDictList.xml b/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/CatalogTool_getContentTranslationDictList.xml
index ee7fd22458..427394053a 100644
--- a/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/CatalogTool_getContentTranslationDictList.xml
+++ b/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/CatalogTool_getContentTranslationDictList.xml
@@ -51,15 +51,8 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>from Products.ERP5Type.Utils import convertToUpperCase\n
-\n
-\n
-########### CONFIGURATION ######################################\n
-# If you want to index properties more, extend property_list   #\n
-# and portal_type_list.                                        #\n
-################################################################\n
-property_list = (\'title\',)\n
-portal_type_list = (\'Person\',)\n
-\n
+portal = context.getPortalObject()\n
+portal_type_property_mapping = portal.ERP5Site_getPortalTypeContentTranslationMapping()\n
 \n
 result = []\n
 \n
@@ -69,10 +62,12 @@ def upperCase(text):\n
 content_language_list = context.Localizer.get_languages()\n
 \n
 for document in document_list:\n
-  if document.getPortalType() not in portal_type_list:\n
+  portal_type = document.getPortalType()\n
+  if portal_type not in portal_type_property_mapping:\n
     continue\n
+  \n
   uid = document.getUid()\n
-  for property_name in property_list:\n
+  for property_name in portal_type_property_mapping[portal_type]:\n
     temporary_result = []\n
 \n
     original_text = None\n
diff --git a/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/ERP5Site_getPortalTypeContentTranslationMapping.xml b/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/ERP5Site_getPortalTypeContentTranslationMapping.xml
new file mode 100644
index 0000000000..070b7c4090
--- /dev/null
+++ b/bt5/erp5_content_translation/SkinTemplateItem/portal_skins/erp5_content_translation/ERP5Site_getPortalTypeContentTranslationMapping.xml
@@ -0,0 +1,88 @@
+<?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>_Cacheable__manager_id</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>from Products.ERP5Type.Cache import CachingMethod\n
+\n
+def getPortalTypeContentTranslationMapping():\n
+  result = dict()\n
+  for type_information in context.getPortalObject().portal_types.listTypeInfo():\n
+    content_translation_domain_property_name_list =\\\n
+      type_information.getContentTranslationDomainPropertyNameList()\n
+    if content_translation_domain_property_name_list:\n
+      result[type_information.getId()] = content_translation_domain_property_name_list\n
+  return result    \n
+\n
+getPortalTypeContentTranslationMapping = CachingMethod(\n
+  getPortalTypeContentTranslationMapping,\n
+      id=script.id, \n
+      cache_factory=\'erp5_content_long\')\n
+return getPortalTypeContentTranslationMapping()\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>ERP5Site_getPortalTypeContentTranslationMapping</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_content_translation/bt/revision b/bt5/erp5_content_translation/bt/revision
index d2e1cefe89..7d37386284 100644
--- a/bt5/erp5_content_translation/bt/revision
+++ b/bt5/erp5_content_translation/bt/revision
@@ -1 +1 @@
-44
\ No newline at end of file
+45
\ No newline at end of file
-- 
2.30.9