Commit 7c3f182a authored by Mario Jorge Amaral's avatar Mario Jorge Amaral

Implementation of getChapterItem.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43951 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ef8da5bd
...@@ -219,14 +219,14 @@ class OOGranulator(object): ...@@ -219,14 +219,14 @@ class OOGranulator(object):
def _getChapterList(self): def _getChapterList(self):
""" This should use memcache or another cache infrastructure. """ This should use memcache or another cache infrastructure.
""" """
RELEVANT_CHAPTER_CACHE = getattr(self, "RELEVANT_CHAPTER_CACHE", None) CHAPTER_CACHE = getattr(self, "CHAPTER_CACHE", None)
if RELEVANT_CHAPTER_CACHE is None: if CHAPTER_CACHE is None:
relevant_chapter_list = self.document.parsed_content.xpath( chapter_list = self.document.parsed_content.xpath(
CHAPTER_XPATH_QUERY, CHAPTER_XPATH_QUERY,
namespaces=self.document.parsed_content.nsmap) namespaces=self.document.parsed_content.nsmap)
setattr(self, "RELEVANT_CHAPTER_CACHE", relevant_chapter_list) setattr(self, "CHAPTER_CACHE", chapter_list)
return self.RELEVANT_CHAPTER_CACHE return self.CHAPTER_CACHE
def getChapterItemList(self): def getChapterItemList(self):
"""Returns the list of chapters in the form of (id, level).""" """Returns the list of chapters in the form of (id, level)."""
...@@ -239,7 +239,14 @@ class OOGranulator(object): ...@@ -239,7 +239,14 @@ class OOGranulator(object):
def getChapterItem(self, chapter_id): def getChapterItem(self, chapter_id):
"""Return the chapter in the form of (title, level).""" """Return the chapter in the form of (title, level)."""
raise NotImplementedError chapter_list = self._getChapterList()
try:
chapter = chapter_list[chapter_id].encode('utf-8')
return [chapter_id, chapter]
except IndexError:
msg = "Unable to find chapter %s at chapter list." % chapter_id
logger.error(msg)
return None
def trash(self): def trash(self):
"""Remove the file in memory.""" """Remove the file in memory."""
......
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