Commit 20adb980 authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Add getTableMatrix for oogranulate


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41840 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 955051f4
1.0.10 (unreleased) 1.0.10 (unreleased)
=================== ===================
- Refactor code to use json instead of jsonpickle. - Refactor code to use json instead of jsonpickle.
- Add getTableItem and getTableItemList for OOGranulate - Add getTableItem, getTableItemList and getTableMatrix for OOGranulate
- Add getParagraphItemList and getParagraphItem for OOGranulate - Add getParagraphItemList and getParagraphItem for OOGranulate
- Add getImageItemList and getImage for OOGranulate - Add getImageItemList and getImage for OOGranulate
- Add OdfDocument - Add OdfDocument
......
...@@ -123,6 +123,23 @@ class OOGranulate(object): ...@@ -123,6 +123,23 @@ class OOGranulate(object):
logger.error(e) logger.error(e)
return None return None
def getTableMatrix(self, id):
"""Returns the table as a matrix"""
row_list = self.document.parsed_content.xpath(
'//table:table[@table:name="%s"]/table:table-row' % id,
namespaces=self.document.parsed_content.nsmap)
if len(row_list) == 0:
return None
matrix = []
for row in row_list:
matrix_row = []
for cell in row.iterchildren():
matrix_row.append(''.join(cell.itertext()))
matrix.append(matrix_row)
return matrix
def getColumnItemList(self, file, table_id): def getColumnItemList(self, file, table_id):
"""Return the list of columns in the form of (id, title).""" """Return the list of columns in the form of (id, title)."""
raise NotImplementedError raise NotImplementedError
......
...@@ -38,6 +38,9 @@ class ITableGranulator(Interface): ...@@ -38,6 +38,9 @@ class ITableGranulator(Interface):
def getTableItem(id, format): def getTableItem(id, format):
"""Returns the table into a new 'format' file.""" """Returns the table into a new 'format' file."""
def getTableMatrix(self, id):
"""Returns the table as a matrix."""
def getColumnItemList(file, table_id): def getColumnItemList(file, table_id):
"""Return the list of columns in the form of (id, title).""" """Return the list of columns in the form of (id, title)."""
......
...@@ -56,10 +56,11 @@ class TestInterface(unittest.TestCase): ...@@ -56,10 +56,11 @@ class TestInterface(unittest.TestCase):
def testITableGranulator(self): def testITableGranulator(self):
"""Test if OOGranulate implements ITableGranulator""" """Test if OOGranulate implements ITableGranulator"""
self.assertEquals(ITableGranulator.implementedBy(OOGranulate), True) self.assertEquals(ITableGranulator.implementedBy(OOGranulate), True)
method_list = ['getTableItem', method_list = ['getColumnItemList',
'getLineItemList', 'getLineItemList',
'getColumnItemList', 'getTableItem',
'getTableItemList'] 'getTableItemList',
'getTableMatrix']
self.assertEquals(ITableGranulator.names(), method_list) self.assertEquals(ITableGranulator.names(), method_list)
def testITextGranulator(self): def testITextGranulator(self):
......
...@@ -83,6 +83,24 @@ class TestOOGranulate(cloudoooTestCase): ...@@ -83,6 +83,24 @@ class TestOOGranulate(cloudoooTestCase):
table_data = oogranulate.getTableItem('NonExistentTable') table_data = oogranulate.getTableItem('NonExistentTable')
self.assertEquals(table_data, None) self.assertEquals(table_data, None)
def testGetTableMatriz(self):
"""Test if getTableMatrix() returns the right matrix"""
data = open('./data/granulate_table_test.odt').read()
oogranulate = OOGranulate(data, 'odt')
matrix = [['Name', 'Phone', 'Email'],
['Hugo', '+55 (22) 8888-8888', 'hugomaia@tiolive.com'],
['Rafael', '+55 (22) 9999-9999', 'rafael@tiolive.com']]
self.assertEquals(matrix, oogranulate.getTableMatrix('Developers'))
matrix = [['Product', 'Price'],
['Pizza', 'R$ 25,00'],
['Petit Gateau', 'R$ 10,00'],
['Feijoada', 'R$ 30,00']]
self.assertEquals(matrix, oogranulate.getTableMatrix('Prices'))
self.assertEquals(None, oogranulate.getTableMatrix('Non existent'))
def testGetColumnItemList(self): def testGetColumnItemList(self):
"""Test if getColumnItemList() returns the right table columns list""" """Test if getColumnItemList() returns the right table columns list"""
self.assertRaises(NotImplementedError, self.oogranulate.getColumnItemList, self.assertRaises(NotImplementedError, self.oogranulate.getColumnItemList,
......
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