From a84ad2fedeb336a5989c1e92ff5f50a1d4cfadf4 Mon Sep 17 00:00:00 2001 From: Jean-Paul Smets <jp@nexedi.com> Date: Mon, 7 Apr 2008 20:48:24 +0000 Subject: [PATCH] Support converted size git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20332 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/ERP5/Document/Document.py | 33 +++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/product/ERP5/Document/Document.py b/product/ERP5/Document/Document.py index f33907754e..84c8e9b981 100644 --- a/product/ERP5/Document/Document.py +++ b/product/ERP5/Document/Document.py @@ -135,7 +135,7 @@ class ConversionCacheMixin: """ self._cached_time = PersistentMapping() self._cached_data = PersistentMapping() - self._cached_mime = PersistentMapping() + self._cached_size = PersistentMapping() security.declareProtected(Permissions.View, 'updateConversionCache') def updateConversionCache(self): @@ -144,8 +144,8 @@ class ConversionCacheMixin: self._cached_time = PersistentMapping() if not hasattr(aself, '_cached_data') or self._cached_data is None: self._cached_data = PersistentMapping() - if not hasattr(aself, '_cached_mime') or self._cached_mime is None: - self._cached_mime = PersistentMapping() + if not hasattr(aself, '_cached_size') or self._cached_size is None: + self._cached_size = PersistentMapping() security.declareProtected(Permissions.View, 'hasConversion') def hasConversion(self, **format): @@ -183,6 +183,9 @@ class ConversionCacheMixin: # is useful to remove the wrapper from a temp object # which may have been used to generate data self.updateConversion(**format) + self._cached_size[tformat] = len(data) + else: + self._cached_size[tformat] = 0 self._p_changed = 1 security.declareProtected(Permissions.View, 'getConversion') @@ -198,7 +201,18 @@ class ConversionCacheMixin: """ self.updateConversionCache() tformat = makeSortedTuple(format) - return self._cached_mime.get(tformat, ''), self._cached_data.get(tformat, '') + return self._cached_mime[tformat], self._cached_data[tformat] + + security.declareProtected(Permissions.View, 'getConversionSize') + def getConversionSize(self, **format): + """ + Returns the size of the converted document. + """ + self.updateConversionCache() + tformat = makeSortedTuple(format) + if not self._cached_size.has_key(tformat): + self._cached_size[tformat] = len(self._cached_data[tformat]) + return self._cached_size[tformat] security.declareProtected(Permissions.ViewManagementScreens, 'getConversionCacheInfo') def getConversionCacheInfo(self): @@ -1138,11 +1152,18 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna formats require certain permission """ if format == 'html': - return 'text/html', '' + return 'text/html', '' # XXX - Why ? if format in ('text', 'txt'): - return 'text/plain', '' + return 'text/plain', '' # XXX - Why ? raise NotImplementedError + def getConvertedSize(self, format): + """ + Returns the size of the converted document + """ + format, data = self.convert(format) + return len(data) + security.declareProtected(Permissions.View, 'asText') def asText(self): """ -- 2.30.9