Commit a84ad2fe authored by Jean-Paul Smets's avatar Jean-Paul Smets

Support converted size

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20332 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 979a07d5
...@@ -135,7 +135,7 @@ class ConversionCacheMixin: ...@@ -135,7 +135,7 @@ class ConversionCacheMixin:
""" """
self._cached_time = PersistentMapping() self._cached_time = PersistentMapping()
self._cached_data = PersistentMapping() self._cached_data = PersistentMapping()
self._cached_mime = PersistentMapping() self._cached_size = PersistentMapping()
security.declareProtected(Permissions.View, 'updateConversionCache') security.declareProtected(Permissions.View, 'updateConversionCache')
def updateConversionCache(self): def updateConversionCache(self):
...@@ -144,8 +144,8 @@ class ConversionCacheMixin: ...@@ -144,8 +144,8 @@ class ConversionCacheMixin:
self._cached_time = PersistentMapping() self._cached_time = PersistentMapping()
if not hasattr(aself, '_cached_data') or self._cached_data is None: if not hasattr(aself, '_cached_data') or self._cached_data is None:
self._cached_data = PersistentMapping() self._cached_data = PersistentMapping()
if not hasattr(aself, '_cached_mime') or self._cached_mime is None: if not hasattr(aself, '_cached_size') or self._cached_size is None:
self._cached_mime = PersistentMapping() self._cached_size = PersistentMapping()
security.declareProtected(Permissions.View, 'hasConversion') security.declareProtected(Permissions.View, 'hasConversion')
def hasConversion(self, **format): def hasConversion(self, **format):
...@@ -183,6 +183,9 @@ class ConversionCacheMixin: ...@@ -183,6 +183,9 @@ class ConversionCacheMixin:
# is useful to remove the wrapper from a temp object # is useful to remove the wrapper from a temp object
# which may have been used to generate data # which may have been used to generate data
self.updateConversion(**format) self.updateConversion(**format)
self._cached_size[tformat] = len(data)
else:
self._cached_size[tformat] = 0
self._p_changed = 1 self._p_changed = 1
security.declareProtected(Permissions.View, 'getConversion') security.declareProtected(Permissions.View, 'getConversion')
...@@ -198,7 +201,18 @@ class ConversionCacheMixin: ...@@ -198,7 +201,18 @@ class ConversionCacheMixin:
""" """
self.updateConversionCache() self.updateConversionCache()
tformat = makeSortedTuple(format) 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') security.declareProtected(Permissions.ViewManagementScreens, 'getConversionCacheInfo')
def getConversionCacheInfo(self): def getConversionCacheInfo(self):
...@@ -1138,11 +1152,18 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna ...@@ -1138,11 +1152,18 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna
formats require certain permission formats require certain permission
""" """
if format == 'html': if format == 'html':
return 'text/html', '' return 'text/html', '' # XXX - Why ?
if format in ('text', 'txt'): if format in ('text', 'txt'):
return 'text/plain', '' return 'text/plain', '' # XXX - Why ?
raise NotImplementedError 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') security.declareProtected(Permissions.View, 'asText')
def asText(self): def asText(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