Commit a65b909e authored by Bartek Górny's avatar Bartek Górny

convertToBase moved to Document as generic method; fixed calls to processing status workflow;

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13256 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 93f0fe48
...@@ -320,6 +320,7 @@ class Document(XMLObject): ...@@ -320,6 +320,7 @@ class Document(XMLObject):
'subject', 'source_reference', 'source_project_title') 'subject', 'source_reference', 'source_project_title')
data = '' # some day this will be in property sheets data = '' # some day this will be in property sheets
base_format = 'base storage format'
### Content processing methods ### Content processing methods
security.declareProtected(Permissions.View, 'index_html') security.declareProtected(Permissions.View, 'index_html')
...@@ -900,13 +901,44 @@ class Document(XMLObject): ...@@ -900,13 +901,44 @@ class Document(XMLObject):
return self._getTypeBasedMethod('finishIngestion', return self._getTypeBasedMethod('finishIngestion',
fallback_script_id='Document_finishIngestion') fallback_script_id='Document_finishIngestion')
def convertToBase(self): security.declareProtected(Permissions.View, 'convert')
def convertToBase(self, REQUEST=None):
"""
This is run upon upload of the file to make the first
conversion; calls _convertToBase which be default does
nothing.
Records the result in processing_status_workflow
In OOo documents it converts into ODF format so that we can easily
convert into other formats, play with metadata and such.
In PDF doc it converts to plain text, so that we don't have to
reconvert every time we reindex the object.
"""
try:
msg = self._convertToBase()
if msg is None:
msg = 'Converted to %s.' % self.base_format
self.convertFile(comment=msg) # Invoke workflow method
except NotImplementedError:# we don't do any workflow action if nothing has been done
msg = ''
except ConversionError, e:
msg = 'Problem: %s' % (str(e) or 'undefined.')
self.processFile(comment=msg)
except Fault, e:
msg = 'Problem: %s' % (repr(e) or 'undefined.')
self.processFile(comment=msg)
except socket.error, e:
msg = 'Problem: %s' % (repr(e) or 'undefined.')
self.processFile(comment=msg)
return msg
def _convertToBase(self):
""" """
API method - some subclasses store data in a certain 'base' format API method - some subclasses store data in a certain 'base' format
(e.g. OOoDocument uses ODF) (e.g. OOoDocument uses ODF)
XXX-JPS What is this ? Explain. Name unclear XXX-JPS What is this ? Explain. Name unclear
""" """
pass raise NotImplementedError
# vim: filetype=python syntax=python shiftwidth=2 # vim: filetype=python syntax=python shiftwidth=2
...@@ -139,7 +139,6 @@ class PDFDocument(File, ConversionCacheMixin): ...@@ -139,7 +139,6 @@ class PDFDocument(File, ConversionCacheMixin):
We mark it in cache as done, even if we fail, so we don't keep trying if it We mark it in cache as done, even if we fail, so we don't keep trying if it
doesn't work. doesn't work.
""" """
portal_workflow = getToolByName(self, 'portal_workflow')
if hasattr(self, 'data') and (force == 1 or not self.hasConversion(format = 'txt')): if hasattr(self, 'data') and (force == 1 or not self.hasConversion(format = 'txt')):
# XXX-JPS accessing attribute data is bad # XXX-JPS accessing attribute data is bad
self.log('PdfDocument', 'regenerating txt') self.log('PdfDocument', 'regenerating txt')
...@@ -159,13 +158,17 @@ class PDFDocument(File, ConversionCacheMixin): ...@@ -159,13 +158,17 @@ class PDFDocument(File, ConversionCacheMixin):
else: else:
msg = 'Converted to text' msg = 'Converted to text'
finally: finally:
portal_workflow.doActionFor(self, 'process', comment=msg) self.processFile(comment=msg)
# we don't need to store it twice, just mark we have it (or rather we already tried) # we don't need to store it twice, just mark we have it (or rather we already tried)
# we try only once # we try only once
self.setConversion('empty', format = 'txt') self.setConversion('empty', format = 'txt')
SearchableText=getSearchableText SearchableText=getSearchableText
security.declarePrivate('_convertToBase')
def _convertToBase(self):
self._convertToText(force=1)
security.declareProtected(Permissions.View, 'getHtmlRepresentation') security.declareProtected(Permissions.View, 'getHtmlRepresentation')
def getHtmlRepresentation(self, force=0): def getHtmlRepresentation(self, force=0):
''' '''
......
...@@ -132,6 +132,8 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -132,6 +132,8 @@ class OOoDocument(File, ConversionCacheMixin):
'mode' : ''}, 'mode' : ''},
) )
base_format = 'Open Document Format'
# regexps for stripping xml from docs # regexps for stripping xml from docs
rx_strip = re.compile('<[^>]*?>', re.DOTALL|re.MULTILINE) rx_strip = re.compile('<[^>]*?>', re.DOTALL|re.MULTILINE)
rx_compr = re.compile('\s+') rx_compr = re.compile('\s+')
...@@ -195,28 +197,6 @@ class OOoDocument(File, ConversionCacheMixin): ...@@ -195,28 +197,6 @@ class OOoDocument(File, ConversionCacheMixin):
m = Message(domain='ui', message=msg) m = Message(domain='ui', message=msg)
return (code, m) return (code, m)
security.declareProtected(Permissions.View, 'convert')
def convertToBase(self, REQUEST=None):
"""
Converts from the initial format to base format (ODF);
communicates with the conversion server
and gets converted file as well as metadata
"""
try:
self._convertToBase()
msg = 'Converted to Open Document Format.'
self.convertFile(comment=msg) # Invoke workflow method
except ConversionError, e:
msg = 'Problem: %s' % (str(e) or 'undefined.')
self.processFile(comment=msg)
except Fault, e:
msg = 'Problem: %s' % (repr(e) or 'undefined.')
self.processFile(comment=msg)
except socket.error, e:
msg = 'Problem: %s' % (repr(e) or 'undefined.')
self.processFile(comment=msg)
return msg
security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList') security.declareProtected(Permissions.AccessContentsInformation,'getTargetFormatList')
def getTargetFormatItemList(self): def getTargetFormatItemList(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