[Erp5-report] r41967 lucas - in /erp5/trunk/bt5/erp5_configurator: ExtensionTemplateItem/ bt/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jan 4 00:53:17 CET 2011


Author: lucas
Date: Tue Jan  4 00:53:16 2011
New Revision: 41967

URL: http://svn.erp5.org?rev=41967&view=rev
Log:
2010-01-03 lucas
* Moved the extension ConfigurationTemplate_readOOoCalcFile to this bt5.

Added:
    erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/
    erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/ConfigurationTemplate_readOOoCalcFile.py
    erp5/trunk/bt5/erp5_configurator/bt/template_extension_id_list
Modified:
    erp5/trunk/bt5/erp5_configurator/bt/change_log
    erp5/trunk/bt5/erp5_configurator/bt/revision

Added: erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/ConfigurationTemplate_readOOoCalcFile.py
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/ConfigurationTemplate_readOOoCalcFile.py?rev=41967&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/ConfigurationTemplate_readOOoCalcFile.py (added)
+++ erp5/trunk/bt5/erp5_configurator/ExtensionTemplateItem/ConfigurationTemplate_readOOoCalcFile.py [utf8] Tue Jan  4 00:53:16 2011
@@ -0,0 +1,126 @@
+##############################################################################
+#
+# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
+#                    Romain Courteaud <romain at nexedi.com>
+#                    Ivan Tyagov <ivan at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+import StringIO
+
+def read(self, filename):
+  """
+  Return a OOCalc as a StringIO
+  """
+  oo_template_file = getattr(self, filename)
+  fp = StringIO.StringIO(oo_template_file)
+  fp.filename = filename
+  return fp
+
+def getIdFromString(string):
+  """
+    This function transform a string to a safe id.
+    It is used here to create a safe category id from a string.
+  """
+  if string is None:
+    return None
+  clean_id = ''
+  translation_map = { "a": ['\xe0']
+                    , "e": ['\xe9', '\xe8']
+                    }
+  #string = string.lower()
+  string = string.strip()
+  # oocalc inserts some strange chars when you press - key in a text cell.
+  # Following line is a workaround for this, 
+  # because \u2013 does not exist in latin1
+  string = string.replace(u'\u2013', '-')
+  for char in string.encode('utf-8'):#('iso8859_1'):
+    if char == '_' or char.isalnum():
+      clean_id += char
+    elif char.isspace() or char in ('+', '-'):
+      clean_id += '_'
+    else:
+      for (safe_char, char_list) in translation_map.items():
+        if char in char_list:
+          clean_id += safe_char
+          break
+  return clean_id
+
+def convert(self, filename):
+  from Products.ERP5OOo.OOoUtils import OOoParser
+  OOoParser = OOoParser()
+  import_file = read(self, filename)
+
+  # Extract tables from the speadsheet file
+  OOoParser.openFile(import_file)
+  filename = OOoParser.getFilename()
+  spreadsheets = OOoParser.getSpreadsheetsMapping()
+
+  table_dict = {}
+  for table_name, table in spreadsheets.items():
+    if not table:
+      continue
+    # Get the header of the table
+    columns_header = table[0]
+    # Get the mapping to help us to know the property according a cell index
+    property_map = {}
+    column_index = 0
+    for column in columns_header:
+      column_id = getIdFromString(column)
+      # The column has no header information
+      # The column has a normal header
+      property_map[column_index] = column_id
+      column_index += 1
+
+    # Construct categories data (with absolut path) from table lines
+    object_list = []
+
+    for line in table[1:]:
+      object_property_dict = {}
+
+      # Exclude empty lines
+      if line.count('') + line.count(None) == len(line):
+        continue
+
+      # Analyse every cells of the line
+      cell_index = 0
+      for cell in line:
+        # Ignore empty cells, do the test on the generated id 
+        # because getIdFromString() is more restrictive
+        cell_id = getIdFromString(cell)
+        if cell_id not in ('', None):
+          # Get the property corresponding to the cell data
+          property_id = property_map[cell_index]
+          # Convert the value to something like '\xc3\xa9' not '\xc3\xa9'
+          object_property_dict[property_id] = cell.encode('UTF-8')
+        cell_index += 1
+
+      if len(object_property_dict) > 0:
+        object_list.append(object_property_dict)
+    table_dict[table_name.encode('UTF-8')] = object_list
+
+  if len(table_dict.keys()) == 1:
+    return object_list
+  else:
+    return table_dict

Modified: erp5/trunk/bt5/erp5_configurator/bt/change_log
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_configurator/bt/change_log?rev=41967&r1=41966&r2=41967&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_configurator/bt/change_log [utf8] (original)
+++ erp5/trunk/bt5/erp5_configurator/bt/change_log [utf8] Tue Jan  4 00:53:16 2011
@@ -1,3 +1,6 @@
+2010-01-03 lucas
+* Moved the extension ConfigurationTemplate_readOOoCalcFile to this bt5.
+
 2010-01-01 lucas
 * Added proxy field in all forms, using base configurator field library.
 

Modified: erp5/trunk/bt5/erp5_configurator/bt/revision
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_configurator/bt/revision?rev=41967&r1=41966&r2=41967&view=diff
==============================================================================
--- erp5/trunk/bt5/erp5_configurator/bt/revision [utf8] (original)
+++ erp5/trunk/bt5/erp5_configurator/bt/revision [utf8] Tue Jan  4 00:53:16 2011
@@ -1 +1 @@
-463
\ No newline at end of file
+464
\ No newline at end of file

Added: erp5/trunk/bt5/erp5_configurator/bt/template_extension_id_list
URL: http://svn.erp5.org/erp5/trunk/bt5/erp5_configurator/bt/template_extension_id_list?rev=41967&view=auto
==============================================================================
--- erp5/trunk/bt5/erp5_configurator/bt/template_extension_id_list (added)
+++ erp5/trunk/bt5/erp5_configurator/bt/template_extension_id_list [utf8] Tue Jan  4 00:53:16 2011
@@ -0,0 +1 @@
+ConfigurationTemplate_readOOoCalcFile
\ No newline at end of file



More information about the Erp5-report mailing list