Commit 8b120874 authored by Bryton Lacquement's avatar Bryton Lacquement 🚪

Document/{File,PDFDocument}: drop the precondition to edit a file

'precondition' was an attribute from Products.CMFDefault. As we dropped
the latter, and the attribute has never been used in ERP5, we can delete
it.
parent ed4eb2d4
......@@ -346,9 +346,9 @@ class PDFDocument(Image):
self._content_information = result
return result.copy()
def _setFile(self, data, precondition=None):
def _setFile(self, data):
try:
del self._content_information
except (AttributeError, KeyError):
pass
Image._setFile(self, data, precondition=precondition)
Image._setFile(self, data)
......@@ -101,7 +101,6 @@ class File(Document, OFS_File):
"""
if 'file' in kw:
file_object = kw.pop('file')
precondition = kw.get('precondition')
filename = getattr(file_object, 'filename', None)
# if file field is empty(no file is uploaded),
# filename is empty string.
......@@ -119,7 +118,7 @@ class File(Document, OFS_File):
file_object.seek(0, 2)
if file_object.tell():
file_object.seek(0)
self._setFile(file_object, precondition=precondition)
self._setFile(file_object)
Base._edit(self, **kw)
security.declareProtected( Permissions.ModifyPortalContent, 'edit' )
......@@ -145,22 +144,20 @@ class File(Document, OFS_File):
"""
return None
def _setFile(self, data, precondition=None):
if data is not None and \
str(data.read()) == (self.hasData() and str(self.getData())):
def _setFile(self, data):
if data is None:
return
if str(data.read()) == (self.hasData() and str(self.getData())):
# Same data as previous, no need to change its content
return
# from Products.CMFDefault.File
if precondition: self.precondition = precondition
elif self.precondition: del self.precondition
if data is not None and data.tell():
if data.tell():
data.seek(0)
self.manage_upload(data)
security.declareProtected(Permissions.ModifyPortalContent,'setFile')
def setFile(self, data, precondition=None):
self._setFile(data, precondition=precondition)
def setFile(self, data):
self._setFile(data)
self.reindexObject()
security.declareProtected(Permissions.AccessContentsInformation, 'hasFile')
......
......@@ -69,7 +69,6 @@ class TestFormPrintoutAsODG(TestFormPrintoutMixin):
addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
if custom._getOb('Foo_getODGStyleSheet', None) is None:
addStyleSheet(id='Foo_getODGStyleSheet', file=foo_file, title='',
precondition='',
content_type='application/vnd.oasis.opendocument.graphics')
erp5OOo = custom.manage_addProduct['ERP5OOo']
......
......@@ -84,23 +84,22 @@ class TestFormPrintoutAsODT(TestFormPrintoutMixin):
addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
if custom._getOb('Foo_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo_getODTStyleSheet', file=foo_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo2_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo2_getODTStyleSheet', file=foo2_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo3_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo3_getODTStyleSheet', file=foo3_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo4_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo4_getODTStyleSheet', file=foo4_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo5_getODTStyleSheet', None) is None:
addStyleSheet(id='Foo5_getODTStyleSheet', file=foo5_file, title='',
precondition='', content_type = 'application/vnd.oasis.opendocument.text')
content_type = 'application/vnd.oasis.opendocument.text')
if custom._getOb('Foo_getVariableODTStyleSheet', None) is None:
addStyleSheet(id='Foo_getVariableODTStyleSheet',
file=variable_file_object, title='',
precondition='',
content_type='application/vnd.oasis.opendocument.text')
erp5OOo = custom.manage_addProduct['ERP5OOo']
......
......@@ -67,7 +67,7 @@ class TestOoodResponse(ERP5TypeTestCase):
custom = portal_skins.custom
addStyleSheet = custom.manage_addProduct['OFSP'].manage_addFile
addStyleSheet(id='Base_getODTStyleSheet', file=import_file, title='',
precondition='', content_type='application/vnd.oasis.opendocument.text')
content_type='application/vnd.oasis.opendocument.text')
addOOoTemplate = custom.manage_addProduct['ERP5OOo'].addOOoTemplate
addOOoTemplate(id='ERP5Site_viewNothingAsOdt', title='')
portal_skins.changeSkin(skinname=None)
......
......@@ -76,10 +76,10 @@ class TestOooDynamicStyle(ERP5TypeTestCase):
addStyleSheet = self.getPortal().manage_addProduct['OFSP'].manage_addFile
if getattr(self.getPortal(), 'Test_getODTStyleSheet_en', None) is None:
addStyleSheet(id='Test_getODTStyleSheet_en', file=en_file, title='',
precondition='', content_type=self.content_type_writer)
content_type=self.content_type_writer)
if getattr(self.getPortal(), 'Test_getODTStyleSheet_ja', None) is None:
addStyleSheet(id='Test_getODTStyleSheet_ja', file=ja_file, title='',
precondition='', content_type=self.content_type_writer)
content_type=self.content_type_writer)
if getattr(self.getPortal(), 'Base_getODTStyleSheetByLanguage', None) is None:
script_body = """
current_language = context.Localizer.get_selected_language()
......
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