From c03c0f4f505c03c92b43fc9ce4ab61f614e2ea71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 10 Sep 2007 12:01:53 +0000
Subject: [PATCH] fix get_size to use base_data if no data

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16221 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/File.py    |  8 ++++----
 product/ERP5OOo/tests/testDms.py | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/product/ERP5/Document/File.py b/product/ERP5/Document/File.py
index bef6b53489a..64b830b7923 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 bec0c75d9f8..681f3291c16 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:
-- 
2.30.9