diff --git a/product/ERP5/Document/File.py b/product/ERP5/Document/File.py index bef6b53489a6ad25414e7128975236911fa94f8e..64b830b7923a523e818c4c498f3557c06db9f29a 100644 --- a/product/ERP5/Document/File.py +++ b/product/ERP5/Document/File.py @@ -153,10 +153,10 @@ class File(Document, CMFFile, ConversionCacheMixin): """ has to be overwritten here, otherwise WebDAV fails """ - try: - return len(self.data) - except (AttributeError, TypeError): - return 0 + data_len = len(getattr(self, 'data', '')) + if not data_len: + data_len = len(self.getBaseData() or '') + return data_len getcontentlength = get_size diff --git a/product/ERP5OOo/tests/testDms.py b/product/ERP5OOo/tests/testDms.py index bec0c75d9f8210c79dbb1a9cd7e1167a5f384cc6..681f3291c1643af897a365d8e706d8979d55a95c 100644 --- a/product/ERP5OOo/tests/testDms.py +++ b/product/ERP5OOo/tests/testDms.py @@ -425,6 +425,21 @@ class TestDocument(ERP5TypeTestCase): # for REFVER: (3) # for REFVERLANG: (3) + def testOOoDocument_get_size(self): + # test get_size on OOoDocument + doc = self.portal.document_module.newContent(portal_type='Spreadsheet') + doc.edit(file=makeFileUpload('import_data_list.ods')) + self.assertEquals(len(makeFileUpload('import_data_list.ods').read()), + doc.get_size()) + + def testTempOOoDocument_get_size(self): + # test get_size on temporary OOoDocument + from Products.ERP5Type.Document import newTempOOoDocument + doc = newTempOOoDocument(self.portal, 'tmp') + doc.edit(base_data='OOo') + self.assertEquals(len('OOo'), doc.get_size()) + + if __name__ == '__main__': framework() else: