[Erp5-report] r24908 - in /erp5/trunk/products/ERP5/bootstrap/erp5_core: SkinTemplateItem/p...

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Dec 16 17:07:59 CET 2008


Author: jerome
Date: Tue Dec 16 17:07:58 2008
New Revision: 24908

URL: http://svn.erp5.org?rev=24908&view=rev
Log:
Base_getCategoriesSpreadSheetMapping performs checks on the spreadsheet, and can be provided a callback function to report errors to the user.
CategoryTool_importCategoryFile uses this feature to redirect with a portal status message instead of raising an error.

Modified:
    erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.xml
    erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.xml
    erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.xml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.xml?rev=24908&r1=24907&r2=24908&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.xml [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Base_getCategoriesSpreadSheetMapping.xml [utf8] Tue Dec 16 17:07:58 2008
@@ -57,7 +57,12 @@
 
 """Parses a spreadsheet containing categories and returns a mapping.\n
 \n
-import_file must be a spreadsheet in a format supported by openoffice\n
+`import_file` must be a spreadsheet in a format supported by openoffice\n
+\n
+`invalid_spreadsheet_error_handler` is the callback method that will be called if\n
+the spreadsheet is invalid. The method must recieve as only parameter a string\n
+explaining the error.\n
+If no error_callback is given, the default action is to raise a ValueError.\n
 \n
 The returned mapping has the following structure:\n
   \n
@@ -73,9 +78,17 @@
 This scripts guarantees that the list of category info is sorted in such a\n
 way that parent always precedes their children.\n
 """\n
+from Products.ERP5Type.Message import translateString\n
 from Products.ERP5OOo.OOoUtils import OOoParser\n
 parser = OOoParser()\n
 categories_spreadsheet_mapping = dict()\n
+\n
+\n
+def default_invalid_spreadsheet_error_handler(error_message):\n
+  raise ValueError(error_message)\n
+\n
+if invalid_spreadsheet_error_handler is None:\n
+  invalid_spreadsheet_error_handler = default_invalid_spreadsheet_error_handler\n
 \n
 def getIDFromString(string=None):\n
   """\n
@@ -249,12 +262,13 @@
               category_properties[\'title\'] = clean_title\n
 \n
           # Detect duplicate IDs\n
-          #if path_elements and path_elements[-1][\'depth\'] == element_depth:\n
           for element in path_elements[::-1]:\n
             if element[\'depth\'] != element_depth:\n
               break\n
             if element[\'value\'] == path_element_id:\n
-              raise ValueError("Duplicate id %s" % element[\'value\'])\n
+              invalid_spreadsheet_error_handler(\n
+                  translateString("Duplicate id found: ${id}",\n
+                      mapping=dict(id=element[\'value\'])))\n
 \n
           # Save the path element\n
           path_elements.append({ \'depth\': element_depth\n
@@ -280,7 +294,7 @@
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>import_file</string> </value>
+            <value> <string>import_file, invalid_spreadsheet_error_handler=None</string> </value>
         </item>
         <item>
             <key> <string>errors</string> </key>
@@ -300,18 +314,22 @@
                   <dictionary>
                     <item>
                         <key> <string>co_argcount</string> </key>
-                        <value> <int>1</int> </value>
+                        <value> <int>2</int> </value>
                     </item>
                     <item>
                         <key> <string>co_varnames</string> </key>
                         <value>
                           <tuple>
                             <string>import_file</string>
+                            <string>invalid_spreadsheet_error_handler</string>
+                            <string>Products.ERP5Type.Message</string>
+                            <string>translateString</string>
                             <string>Products.ERP5OOo.OOoUtils</string>
                             <string>OOoParser</string>
                             <string>parser</string>
                             <string>dict</string>
                             <string>categories_spreadsheet_mapping</string>
+                            <string>default_invalid_spreadsheet_error_handler</string>
                             <string>None</string>
                             <string>getIDFromString</string>
                             <string>content_type</string>
@@ -363,7 +381,6 @@
                             <string>element</string>
                             <string>path</string>
                             <string>clean_title</string>
-                            <string>ValueError</string>
                           </tuple>
                         </value>
                     </item>
@@ -375,7 +392,9 @@
         <item>
             <key> <string>func_defaults</string> </key>
             <value>
-              <none/>
+              <tuple>
+                <none/>
+              </tuple>
             </value>
         </item>
         <item>

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.xml
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.xml?rev=24908&r1=24907&r2=24908&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.xml [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/CategoryTool_importCategoryFile.xml [utf8] Tue Dec 16 17:07:58 2008
@@ -95,7 +95,17 @@
 kept_category_counter = 0\n
 \n
 filename = getattr(import_file, \'filename\', \'?\')\n
-categories_spreadsheet_mapping = context.Base_getCategoriesSpreadSheetMapping(import_file)\n
+\n
+def invalid_category_spreadsheet_handler(message):\n
+  # action taken when an invalid spreadsheet is provided.\n
+  # we *raise* a Redirect, because we don\'t want the transaction to succeed\n
+  raise \'Redirect\', \'%s/view?portal_status_message=%s\' % (\n
+                         context.portal_categories.absolute_url(),\n
+                         message)\n
+\n
+categories_spreadsheet_mapping = context.Base_getCategoriesSpreadSheetMapping(import_file,\n
+                                    invalid_spreadsheet_error_handler=invalid_category_spreadsheet_handler)\n
+\n
 \n
 for base_category, categories in \\\n
             categories_spreadsheet_mapping.items():\n
@@ -269,6 +279,7 @@
                             <string>kept_category_counter</string>
                             <string>getattr</string>
                             <string>filename</string>
+                            <string>invalid_category_spreadsheet_handler</string>
                             <string>categories_spreadsheet_mapping</string>
                             <string>_getiter_</string>
                             <string>base_category</string>

Modified: erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision?rev=24908&r1=24907&r2=24908&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision [utf8] (original)
+++ erp5/trunk/products/ERP5/bootstrap/erp5_core/bt/revision [utf8] Tue Dec 16 17:07:58 2008
@@ -1,1 +1,1 @@
-1042
+1043




More information about the Erp5-report mailing list