[Erp5-report] r35224 nicolas - /erp5/trunk/products/ERP5/Document/File.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed May 12 16:40:49 CEST 2010
Author: nicolas
Date: Wed May 12 16:40:42 2010
New Revision: 35224
URL: http://svn.erp5.org?rev=35224&view=rev
Log:
Enable convert feature for File.
* According content_type wrap data into TempDocument who support convert
then return the converted value from this temporary document.
Modified:
erp5/trunk/products/ERP5/Document/File.py
Modified: erp5/trunk/products/ERP5/Document/File.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/File.py?rev=35224&r1=35223&r2=35224&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/File.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/File.py [utf8] Wed May 12 16:40:42 2010
@@ -218,6 +218,89 @@
return (mime_type, content)
+ security.declareProtected(Permissions.AccessContentsInformation, 'convert')
+ def convert(self, format, **kw):
+ """According content_type of data we can proceed some Conversions.
+ The idea is to wrap data into TempDocument who support conversion
+ then return conversion from this temporary document.
+
+ mimetype Class of temp document
+
+ text/???? newTempTextDocument
+ image/???? newTempImage
+ application/pdf newTempPDFDocument
+ [ooo supported content_type list] newTempOOoDocument
+ unknown no conversion supported
+
+ XXX Another idea of implementation from JPS: Changing dynamicaly the Class
+ of persistent_object.
+ for example any instance of File portal_type can follow TextDocument API
+ if content_type is 'text/html' and support conversion features of
+ TextDocument.
+ """
+ content_type = self.getContentType()
+
+ # Build the list of acceptable content_type for OOoDocument
+ # Hopefully this is cached
+ from Products.ERP5Type.Document import newTempOOoDocument
+ temp_odt = newTempOOoDocument(self, 'testOOoOdt')
+ temp_odt.edit(base_content_type='application/vnd.oasis.opendocument.text',
+ base_data='not empty')
+ temp_ods = newTempOOoDocument(self, 'testOOoOds')
+ temp_ods.edit(
+ base_content_type='application/vnd.oasis.opendocument.spreadsheet',
+ base_data='not empty')
+ temp_odg = newTempOOoDocument(self, 'testOOoOdg')
+ temp_odg.edit(base_content_type='application/vnd.oasis.opendocument.draw',
+ base_data='not empty')
+ temp_odb = newTempOOoDocument(self, 'testOOoOdb')
+ temp_odb.edit(base_content_type='application/vnd.oasis.opendocument.base',
+ base_data='not empty')
+
+ supported_ooo_content_type_list = [item[0] for item in\
+ temp_odt.getTargetFormatItemList()]\
+ + [item[0] for item in temp_ods.getTargetFormatItemList()]\
+ + [item[0] for item in temp_odg.getTargetFormatItemList()]\
+ + [item[0] for item in temp_odb.getTargetFormatItemList()]
+ if content_type.startswith('text'):
+ # We can wrap it into TextDocument
+ from Products.ERP5Type.Document import newTempTextDocument
+ temp_document = newTempTextDocument(self, 'temp_%s' % self.getId(),
+ text_content=self.getData(),
+ content_type=content_type)
+ return temp_document.convert(format=format, **kw)
+ elif content_type.startswith('image'):
+ # We can wrap it into Image
+ from Products.ERP5Type.Document import newTempImage
+ temp_document = newTempImage(self, 'temp_%s' % self.getId(),
+ data=self.getData(),
+ content_type=content_type)
+ return temp_document.convert(format=format, **kw)
+ elif content_type == 'application/pdf':
+ # We can wrap it into PDFDocument
+ from Products.ERP5Type.Document import newTempPDFDocument
+ temp_document = newTempPDFDocument(self, 'temp_%s' % self.getId(),
+ data=self.getData(),
+ content_type=content_type)
+ return temp_document.convert(format=format, **kw)
+ elif content_type in supported_ooo_content_type_list:
+ # We can wrap it into OOoDocument
+ temp_document = newTempOOoDocument(self, 'temp_%s' % self.getId(),
+ text_content=self.getData(),
+ content_type=content_type)
+ return temp_document.convert(format=format, **kw)
+ else:
+ # We didn't find suitable wrapper to convert this File
+ if format in VALID_TEXT_FORMAT_LIST:
+ # This is acceptable to return empty string
+ # for a File we can not convert
+ return 'text/plain', ''
+ elif format is None:
+ # No conversion is asked,
+ # we can return safely the file content itself
+ return content_type, self.getData()
+ raise NotImplementedError
+
# CMFFile also brings the IContentishInterface on CMF 2.2, remove it.
removeIContentishInterface(File)
More information about the Erp5-report
mailing list