Commit 5d5e0c49 authored by Jérome Perrin's avatar Jérome Perrin

ERP5: fix content_type property

content_type is a bit special, because CMF's PortalFolderBase also have
a content_type method, so this was confusing ERP5Type dynamic properties
system. When the property was never set, the default value was the
method acquired from PortalFolderBase.

Fixes this by defining conten_type class attribute where needed.

This also fixes an old expected failure test, it's now possible to use
edit(content_type=something) in document without content type property
set. It works now, but thanks to what seems to be outdated code in
_valid_property_id from product/ERP5Type/patches/PropertyManager.py,
because we have stopped setting all properties to None in Base years
ago. For now, this works, but because of an outdated condition in
_valid_property_id. We may revisit later in the future.
parent 42999daf
...@@ -74,7 +74,6 @@ class File(Document, CMFFile): ...@@ -74,7 +74,6 @@ class File(Document, CMFFile):
security.declareObjectProtected(Permissions.AccessContentsInformation) security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default global values # Default global values
content_type = '' # Required for WebDAV support (default value)
data = '' # A hack required to use OFS.Image.index_html without calling OFS.Image.__init__ data = '' # A hack required to use OFS.Image.index_html without calling OFS.Image.__init__
# Default Properties # Default Properties
......
...@@ -1379,10 +1379,7 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1379,10 +1379,7 @@ class TestERP5Base(ERP5TypeTestCase):
self.assertEqual('organisation@example.com', self.assertEqual('organisation@example.com',
organisation.getAlternateEmailCoordinateText()) organisation.getAlternateEmailCoordinateText())
# Marked as expectedFailure as it shall be never possible to use edit method to set def test_content_type_local_property(self):
# local property which would override existing method
@expectedFailure
def test_content_type_property(self):
portal_type = 'Person' portal_type = 'Person'
person_module = self.portal.getDefaultModule(portal_type) person_module = self.portal.getDefaultModule(portal_type)
person = person_module.newContent(portal_type=portal_type) person = person_module.newContent(portal_type=portal_type)
...@@ -1393,6 +1390,20 @@ class TestERP5Base(ERP5TypeTestCase): ...@@ -1393,6 +1390,20 @@ class TestERP5Base(ERP5TypeTestCase):
# edit content_type on document which has no content_type property configured # edit content_type on document which has no content_type property configured
person.edit(content_type='text/xml') person.edit(content_type='text/xml')
def test_EmbeddedFile_content_type(self):
embedded_file = self.portal.person_module.newContent(
portal_type='Person'
).newContent(
portal_type='Embedded File'
)
self.assertFalse(embedded_file.hasContentType())
self.assertEqual('text/plain', embedded_file.getContentType('text/plain'))
embedded_file.edit(content_type='text/xml')
self.assertEqual('text/xml', embedded_file.getContentType())
self.assertEqual('text/xml', embedded_file.getProperty('content_type'))
def test_BankAccount_validateIBAN(self): def test_BankAccount_validateIBAN(self):
self.assertTrue( self.assertTrue(
self.portal.BankAccount_validateIBAN( self.portal.BankAccount_validateIBAN(
......
...@@ -637,6 +637,12 @@ class ERP5Form(Base, ZMIForm, ZopePageTemplate): ...@@ -637,6 +637,12 @@ class ERP5Form(Base, ZMIForm, ZopePageTemplate):
objectItems = ZMIForm.objectItems objectItems = ZMIForm.objectItems
objectValues = ZMIForm.objectValues objectValues = ZMIForm.objectValues
# If content_type is not text/html ZopePageTemplate will check that the
# source is well formed XML, but this does not really applies to Forms,
# they don't have source. By setting content_type here we make sure we
# don't get ERP5Type's Base default content_type.
content_type = ZopePageTemplate.content_type
def __init__(self, id, title, unicode_mode=0, encoding='UTF-8', def __init__(self, id, title, unicode_mode=0, encoding='UTF-8',
stored_encoding='UTF-8'): stored_encoding='UTF-8'):
"""Initialize form. """Initialize form.
......
...@@ -847,6 +847,8 @@ class Base( CopyContainer, ...@@ -847,6 +847,8 @@ class Base( CopyContainer,
security.declareProtected( Permissions.AccessContentsInformation, 'getId' ) security.declareProtected( Permissions.AccessContentsInformation, 'getId' )
getId = BaseAccessor.Getter('getId', 'id', 'string') getId = BaseAccessor.Getter('getId', 'id', 'string')
content_type = None # content_type is a property in ERP5, but a method in CMF
# Debug # Debug
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
'getOid') 'getOid')
......
...@@ -707,6 +707,7 @@ class Folder(OFSFolder2, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn): ...@@ -707,6 +707,7 @@ class Folder(OFSFolder2, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn):
PUT_factory = None PUT_factory = None
# XXX Prevent inheritance from PortalFolderBase # XXX Prevent inheritance from PortalFolderBase
description = None description = None
content_type = None # content_type is a property in ERP5, but a method in CMF
# Per default we use BTree folder # Per default we use BTree folder
_folder_handler = BTREE_HANDLER _folder_handler = BTREE_HANDLER
......
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