Commit 9aa32b13 authored by Jérome Perrin's avatar Jérome Perrin

integrate an old patch from mohamadou to handle float, percentage, currency and

date value in getSpreadsheetsMapping, after changing code structure and also
add partial support for time value (there's no equivalent in ERP5, so the raw
string is returned).



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@24599 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4ba48a45
...@@ -444,14 +444,24 @@ class OOoParser(Implicit): ...@@ -444,14 +444,24 @@ class OOoParser(Implicit):
# Ungroup repeated cells # Ungroup repeated cells
for j in range(cells_to_repeat): for j in range(cells_to_repeat):
# Get the cell content # Get the cell content
cell_text = None cell_data = None
text_tags = cell.xpath('.//*[name() = "text:p"]')
if len(text_tags): value_type = cell.getAttributeNS(self.ns['office'], 'value-type')
cell_text = ''.join([text.xpath('string(.)') if value_type == 'date':
for text in text_tags]) cell_data = cell.getAttributeNS(self.ns['office'], 'date-value')
elif value_type == 'time':
cell_data = cell.getAttributeNS(self.ns['office'], 'time-value')
elif value_type in ('float', 'percentage', 'currency'):
cell_data = float(cell.getAttributeNS(
self.ns['office'], 'value'))
else:
text_tags = cell.xpath('.//*[name() = "text:p"]')
if len(text_tags):
cell_data = ''.join([text.xpath('string(.)')
for text in text_tags])
# Add the cell to the line # Add the cell to the line
table_line.append(cell_text) table_line.append(cell_data)
# Delete empty lines if needed # Delete empty lines if needed
if no_empty_lines: if no_empty_lines:
......
...@@ -339,6 +339,24 @@ class TestOOoImport(ERP5TypeTestCase): ...@@ -339,6 +339,24 @@ class TestOOoImport(ERP5TypeTestCase):
self.assertEquals(mapping['Feuille1'][4], self.assertEquals(mapping['Feuille1'][4],
['john.doe@example.com']) ['john.doe@example.com'])
def test_getSpreadSheetMappingDataTypes(self):
parser = OOoParser()
parser.openFile(open(makeFilePath('import_data_list_data_type.ods'), 'rb'))
mapping = parser.getSpreadsheetsMapping()
self.assertEquals(['Feuille1'], mapping.keys())
self.assertEquals(mapping['Feuille1'][0],
[1234.5678])
self.assertEquals(mapping['Feuille1'][1],
[1234.5678])
self.assertEquals(mapping['Feuille1'][2],
[0.1])
self.assertEquals(mapping['Feuille1'][3],
['2008-11-14'])
self.assertEquals(mapping['Feuille1'][4],
['2008-11-14T10:20:30']) # supported by DateTime
self.assertEquals(mapping['Feuille1'][5],
['PT12H34M56S']) # maybe not good, this is raw format
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
File added
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment