Commit dc29520f authored by Hugo H. Maia Vieira's avatar Hugo H. Maia Vieira

Implement getTableItemList


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41359 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 608171ce
1.0.10 (unreleased) 1.0.10 (unreleased)
=================== ===================
- Add getTableItemList 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
......
...@@ -42,9 +42,19 @@ class OOGranulate(object): ...@@ -42,9 +42,19 @@ class OOGranulate(object):
def __init__(self, file, source_format): def __init__(self, file, source_format):
self.document = OdfDocument(file, source_format) self.document = OdfDocument(file, source_format)
def getTableItemList(self, file): def getTableItemList(self):
"""Returns the list of table IDs in the form of (id, title).""" """Returns the list of table IDs in the form of (id, title)."""
raise NotImplementedError xml_table_list = self.document.parsed_content.xpath('.//table:table',
namespaces=self.document.parsed_content.nsmap)
name_key = '{urn:oasis:names:tc:opendocument:xmlns:table:1.0}name'
table_list = []
for table in xml_table_list:
title = ''.join(table.xpath('following-sibling::text:p[position()=1] \
[starts-with(@text:style-name, "Table")]//text()',
namespaces=table.nsmap))
id = table.attrib[name_key]
table_list.append((id, title))
return table_list
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)."""
......
...@@ -32,7 +32,7 @@ from zope.interface import Interface ...@@ -32,7 +32,7 @@ from zope.interface import Interface
class ITableGranulator(Interface): class ITableGranulator(Interface):
"""Provides methods to granulate a document into tables.""" """Provides methods to granulate a document into tables."""
def getTableItemList(file): def getTableItemList():
"""Returns the list of table IDs in the form of (id, title).""" """Returns the list of table IDs in the form of (id, title)."""
def getColumnItemList(file, table_id): def getColumnItemList(file, table_id):
......
...@@ -42,8 +42,12 @@ class TestOOGranulate(cloudoooTestCase): ...@@ -42,8 +42,12 @@ class TestOOGranulate(cloudoooTestCase):
def testgetTableItemList(self): def testgetTableItemList(self):
"""Test if getTableItemList() returns the right tables list""" """Test if getTableItemList() returns the right tables list"""
self.assertRaises(NotImplementedError, self.oogranulate.getTableItemList, data = open('./data/granulate_table_test.odt').read()
'file') oogranulate = OOGranulate(data, 'odt')
table_list = [('Developers', ''),
('Prices', 'Table 1: Prices table from Mon Restaurant'),
('SoccerTeams', 'Tabela 2: Soccer Teams')]
self.assertEquals(table_list, oogranulate.getTableItemList())
def testGetColumnItemList(self): def testGetColumnItemList(self):
"""Test if getColumnItemList() returns the right table columns list""" """Test if getColumnItemList() returns the right table columns list"""
......
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