Commit 30aa085f authored by Jérome Perrin's avatar Jérome Perrin

patches: patch OFS to bring back old __repr__

When updating persistent to >= 4.4 __repr__ of zope objects display
information about ZODB connection, but it's more useful to have
information about the acqusition chain at this level.

One notable case was proxy field error messages, it was supposed to
include the path of the proxy field in the error message. This one is
fixed by fixing the MRO so that persistent.Persistent does not appear
first.
parent fed03caa
...@@ -385,3 +385,26 @@ return printed ...@@ -385,3 +385,26 @@ return printed
form_1_html = form_1.my_field.render(REQUEST=self.app.REQUEST).replace('\n', '') form_1_html = form_1.my_field.render(REQUEST=self.app.REQUEST).replace('\n', '')
form_2_html = form_2.my_field.render(REQUEST=self.app.REQUEST).replace('\n', '') form_2_html = form_2.my_field.render(REQUEST=self.app.REQUEST).replace('\n', '')
self.assertEqual(form_1_html, form_2_html) self.assertEqual(form_1_html, form_2_html)
def test_broken_proxy_field(self):
portal_skins = self.getSkinsTool()
portal_skins.manage_addProduct['OFSP'].manage_addFolder('erp5_geek')
skin_folder = portal_skins._getOb('erp5_geek')
skin_folder.manage_addProduct['ERP5Form'].addERP5Form(
'Base_viewGeek',
'View')
form = skin_folder._getOb('Base_viewGeek', None)
form.manage_addField('my_title', 'Title', 'ProxyField')
field = getattr(form, 'my_title')
self.assertIsNone(field.getTemplateField())
self.assertEqual('', field.render())
self.assertEqual('', field.get_tales('default'))
self.assertIsNone(field.get_value('default'))
with self.assertRaisesRegexp(
AttributeError,
'The proxy field <ProxyField at /%s/portal_skins/erp5_geek/Base_viewGeek/my_title> cannot find a template field'
% self.portal.getId()):
field.get_recursive_tales('default')
from App.special_dtml import DTMLFile from App.special_dtml import DTMLFile
from OFS.Image import File from OFS.Image import File
from OFS.SimpleItem import Item
from Products.ERP5Type import _dtmldir from Products.ERP5Type import _dtmldir
# Patch for displaying textearea in full window instead of # Patch for displaying textearea in full window instead of
...@@ -11,3 +12,7 @@ File.manage = manage_editForm ...@@ -11,3 +12,7 @@ File.manage = manage_editForm
File.manage_main = manage_editForm File.manage_main = manage_editForm
File.manage_editDocument = manage_editForm File.manage_editDocument = manage_editForm
File.manage_editForm = manage_editForm File.manage_editForm = manage_editForm
# restore __repr__ after persistent > 4.4
# https://github.com/zopefoundation/Zope/issues/379
File.__repr__ = Item.__repr__
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass from Products.ERP5Type.Globals import InitializeClass
from OFS.Folder import Folder from OFS.Folder import Folder
from OFS.SimpleItem import Item
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
""" """
...@@ -63,3 +64,7 @@ security = ClassSecurityInfo() ...@@ -63,3 +64,7 @@ security = ClassSecurityInfo()
security.declareProtected(Permissions.ManagePortal, 'isERP5SitePresent') security.declareProtected(Permissions.ManagePortal, 'isERP5SitePresent')
Folder.security = security Folder.security = security
InitializeClass(Folder) InitializeClass(Folder)
# restore __repr__ after persistent > 4.4
# https://github.com/zopefoundation/Zope/issues/379
Folder.__repr__ = Item.__repr__
...@@ -3286,6 +3286,16 @@ return [ ...@@ -3286,6 +3286,16 @@ return [
# but this did not affect the other role # but this did not affect the other role
self.assertTrue(hasRole(role2)) self.assertTrue(hasRole(role2))
def test_repr(self):
document = self.portal.organisation_module.newContent(
portal_type='Organisation',
id='organisation_id'
)
self.assertEqual(
'<Organisation at /%s/organisation_module/organisation_id>' % self.portal.getId(),
repr(document))
class TestAccessControl(ERP5TypeTestCase): class TestAccessControl(ERP5TypeTestCase):
# Isolate test in a dedicaced class in order not to break other tests # Isolate test in a dedicaced class in order not to break other tests
# when this one fails. # when this one fails.
......
...@@ -464,9 +464,9 @@ class Field: ...@@ -464,9 +464,9 @@ class Field:
InitializeClass(Field) InitializeClass(Field)
class ZMIField( class ZMIField(
OFS.SimpleItem.Item,
Acquisition.Implicit, Acquisition.Implicit,
Persistent, Persistent,
OFS.SimpleItem.Item,
Field, Field,
): ):
"""Base class for a field implemented as a Python (file) product. """Base class for a field implemented as a Python (file) product.
......
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