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):
# Ungroup repeated cells
for j in range(cells_to_repeat):
# Get the cell content
cell_text = None
cell_data = None
value_type = cell.getAttributeNS(self.ns['office'], 'value-type')
if value_type == 'date':
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_text = ''.join([text.xpath('string(.)')
cell_data = ''.join([text.xpath('string(.)')
for text in text_tags])
# Add the cell to the line
table_line.append(cell_text)
table_line.append(cell_data)
# Delete empty lines if needed
if no_empty_lines:
......
......@@ -339,6 +339,24 @@ class TestOOoImport(ERP5TypeTestCase):
self.assertEquals(mapping['Feuille1'][4],
['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():
suite = unittest.TestSuite()
......
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