Commit 83635909 authored by Aurel's avatar Aurel

fixup! Get rid of Products.CMFDefault.{File.File,Portal.CMFSite}

See commit 12e4cc8b.

File._setFile does not support that 'data' is a bytes object:
it crashes if there are already data stored on the object.
test_PUT_on_web_page (erp5_dms:testWebDavSupport) is changed to cover
this case and the caller of File._edit is fixed to make that 'file'
is always a file-like object.

File._setFile is also optimized to avoid reading data for nothing
if the document has no data.
parent 1c613aeb
......@@ -186,6 +186,8 @@ class TestWebDavSupport(ERP5TypeTestCase):
"""
iso_text_content = text_content.decode('utf-8').encode('iso-8859-1')
path = web_page_module.getPath()
for _ in xrange(2): # Run twice to check the code that compares
# old & new data when setting file attribute.
response = self.publish('%s/%s' % (path, filename),
request_method='PUT',
stdin=StringIO(iso_text_content),
......
......@@ -36,6 +36,7 @@ from erp5.component.document.Document import ConversionError
from Products.ERP5Type.Base import Base, removeIContentishInterface
from OFS.Image import File as OFS_File
from Products.ERP5Type.Utils import deprecated
from cStringIO import StringIO
def _unpackData(data):
"""
......@@ -146,9 +147,12 @@ class File(Document, OFS_File):
def _setFile(self, data, precondition=None):
if data is None:
return
if str(data.read()) == (self.hasData() and str(self.getData())):
if self.hasData():
if str(data.read()) == str(self.getData()):
# Same data as previous, no need to change its content
return
else:
data.seek(0, 2)
if data.tell():
data.seek(0)
......
......@@ -23,6 +23,7 @@ from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions
from Products.CMFCore.PortalContent import ResourceLockedError
from zExceptions import Forbidden
from cStringIO import StringIO
security = ModuleSecurityInfo(__name__)
......@@ -76,7 +77,7 @@ class TextContent:
headers = self.parseHeadersFromText(body)
content_type = REQUEST.get_header('Content-Type', '')
headers.setdefault('content_type', content_type)
headers['file'] = body
headers['file'] = StringIO(body)
self._edit(**headers)
except ResourceLockedError:
transaction.abort()
......
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