Commit 6d828288 authored by Mario Jorge Amaral's avatar Mario Jorge Amaral

Implementation of getColumnItemList and getLineItemList.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@44638 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0a743834
...@@ -138,22 +138,37 @@ class OOGranulator(object): ...@@ -138,22 +138,37 @@ class OOGranulator(object):
def getColumnItemList(self, table_id): def getColumnItemList(self, 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 row_list = self.document.parsed_content.xpath(
'//table:table[@table:name="%s"]/table:table-row' % table_id,
namespaces=self.document.parsed_content.nsmap)
if len(row_list) == 0:
return None
id = 0
columns = []
for cell in row_list[0].iterchildren():
columns.append([id,''.join(cell.itertext())])
id+=1
return columns
def getLineItemList(self, table_id): def getLineItemList(self, table_id):
"""Returns the lines of a given table as (key, value) pairs.""" """Returns the lines of a given table as (key, value) pairs."""
row_list = self.document.parsed_content.xpath( row_list = self.document.parsed_content.xpath(
'//table:table[@table:name="%s"]/table:table-row' % table_id, '//table:table[@table:name="%s"]/table:table-row' % table_id,
namespaces=self.document.parsed_content.nsmap) namespaces=self.document.parsed_content.nsmap)
if len(row_list) == 0: if len(row_list) == 0:
return None return None
matrix = [] matrix = []
for row in row_list: fields = []
matrix_row = [] for cell_key in row_list[0].iterchildren():
for cell in row.iterchildren(): fields.append(''.join(cell_key.itertext()))
matrix_row.append(''.join(cell.itertext())) for row_values in row_list[1::]:
matrix.append(matrix_row) for cell in row_values.iterchildren():
matrix.append([fields[0], ''.join(cell.itertext())])
fields+=[fields[0]]
fields.remove(fields[0])
return matrix return matrix
def getImageItemList(self): def getImageItemList(self):
......
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