[Erp5-report] r35249 nicolas - /erp5/trunk/products/ERP5OOo/Document/OOoDocument.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed May 12 18:52:25 CEST 2010


Author: nicolas
Date: Wed May 12 18:52:24 2010
New Revision: 35249

URL: http://svn.erp5.org?rev=35249&view=rev
Log:
OOoDocument inherit now from BaseConvertableMixin, TextConvertableMixin and BaseConvertableAndFileMixin.
 * remove all methods defined in these mixin


Modified:
    erp5/trunk/products/ERP5OOo/Document/OOoDocument.py

Modified: erp5/trunk/products/ERP5OOo/Document/OOoDocument.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/Document/OOoDocument.py?rev=35249&r1=35248&r2=35249&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/Document/OOoDocument.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/Document/OOoDocument.py [utf8] Wed May 12 18:52:24 2010
@@ -45,13 +45,15 @@
 from Products.ERP5Type import Permissions, PropertySheet, Constraint
 from Products.ERP5Type.Cache import CachingMethod
 from Products.ERP5.Document.File import File
-from Products.ERP5.Document.Document import PermanentURLMixIn
-from Products.ERP5.Document.Document import ConversionError
-from Products.ERP5.Document.Document import NotConvertedError
+from Products.ERP5.Document.Document import Document, PermanentURLMixIn,\
+VALID_IMAGE_FORMAT_LIST, ConversionError, NotConvertedError
 from zLOG import LOG, ERROR
 
 # Mixin Import
-from Products.ERP5.mixin.cached_convertable import CachedConvertableMixin
+from Products.ERP5.mixin.base_convertable import BaseConvertableMixin
+from Products.ERP5.mixin.text_convertable import TextConvertableMixin
+from Products.ERP5.mixin.base_convertable_and_file import\
+                                                    BaseConvertableAndFileMixin
 
 enc=base64.encodestring
 dec=base64.decodestring
@@ -88,7 +90,8 @@
     return SafeTransport.make_connection(self, h)
 
 
-class OOoDocument(PermanentURLMixIn, File, CachedConvertableMixin):
+class OOoDocument(PermanentURLMixIn, BaseConvertableAndFileMixin, File,
+                  BaseConvertableMixin, TextConvertableMixin, Document):
   """
     A file document able to convert OOo compatible files to
     any OOo supported format, to capture metadata and to
@@ -128,10 +131,6 @@
   # CMF Type Definition
   meta_type = 'ERP5 OOo Document'
   portal_type = 'OOo Document'
-
-  searchable_property_list = ('asText', 'title', 'description', 'id', 'reference',
-                              'version', 'short_title',
-                              'subject', 'source_reference', 'source_project_title',)
 
   # Declarative security
   security = ClassSecurityInfo()
@@ -163,57 +162,6 @@
     OOoDocument is needed to conversion to base format.
     """
     return True
-
-  def _setFile(self, data, precondition=None):
-    File._setFile(self, data, precondition=precondition)
-    if self.hasBaseData():
-      # This is a hack - XXX - new accessor needed to delete properties
-      try:
-        delattr(self, 'base_data')
-      except AttributeError:
-        pass
-
-  security.declareProtected(Permissions.View, 'index_html')
-  def index_html(self, REQUEST, RESPONSE, format=None, display=None, **kw):
-    """
-      Default renderer with conversion support. Format is
-      a string. The list of available formats can be obtained
-      by calling getTargetFormatItemList.
-    """
-    # Accelerate rendering in Web mode
-    _setCacheHeaders(_ViewEmulator().__of__(self), {'format' : format})
-
-    # Verify that the format is acceptable (from permission point of view)
-    method = self._getTypeBasedMethod('checkConversionFormatPermission', 
-        fallback_script_id = 'Document_checkConversionFormatPermission')
-    if not method(format=format):
-      raise Unauthorized("OOoDocument: user does not have enough permission to access document"
-                         " in %s format" % (format or 'original'))
-
-    # Return the original file by default
-    if self.getSourceReference() is not None:
-      filename = self.getSourceReference()
-    else:
-      filename = self.getId()
-    if format is None:
-      RESPONSE.setHeader('Content-Disposition',
-                         'attachment; filename="%s"' % filename)
-      return File.index_html(self, REQUEST, RESPONSE)
-    # Make sure file is converted to base format
-    if not self.hasBaseData():
-      raise NotConvertedError
-    # Else try to convert the document and return it
-    mime, result = self.convert(format=format, display=display, **kw)
-    converted_filename = '%s.%s'%('.'.join(filename.split('.')[:-1]),  format)
-    if not mime:
-      mime = getToolByName(self, 'mimetypes_registry').lookupExtension('name.%s' % format)
-    RESPONSE.setHeader('Content-Length', len(result))
-    RESPONSE.setHeader('Content-Type', mime)
-    RESPONSE.setHeader('Accept-Ranges', 'bytes')
-    if format not in STANDARD_IMAGE_FORMAT_LIST:
-      RESPONSE.setHeader('Content-Disposition',
-                         'attachment; filename="%s"' % converted_filename)
-    return result
 
   # Format conversion implementation
   def _getServerCoordinate(self):
@@ -473,18 +421,13 @@
     else:
       return self.getConversion(format=original_format, display=display)
 
-  security.declareProtected(Permissions.View, 'asTextContent')
+  security.declareProtected(Permissions.AccessContentsInformation,
+                                                               'asTextContent')
   def asTextContent(self):
     """
-      Extract plain text from ooo docs by stripping the XML file.
-      This is the simplest way, the most universal and it is compatible
-      will all formats.
-    """
-    if not self.hasConversion(format='txt'):
-      mime, data = self._convert(format='text-content')
-      self.setConversion(data, mime, format='txt')
-      return mime, data
-    return self.getConversion(format='txt')
+      Backward compatibility
+    """
+    return self.asText()
 
   security.declareProtected(Permissions.ModifyPortalContent,
                             '_populateConversionCacheWithHTML')
@@ -533,15 +476,6 @@
     except KeyError:
       return PermanentURLMixIn._getExtensibleContent(self, request, name)
 
-  # Base format implementation
-  security.declareProtected(Permissions.AccessContentsInformation, 'hasBaseData')
-  def hasBaseData(self):
-    """
-      OOo instances implement conversion to a base format. We should therefore
-      use the default accessor.
-    """
-    return self._baseHasBaseData()
-
   security.declarePrivate('_convertToBaseFormat')
   def _convertToBaseFormat(self):
     """




More information about the Erp5-report mailing list