Commit 01c1218c 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 acquisition chain at this level.

This happens because `persistent.Persistent.__repr__` is used instead of 
`OFS.SimpleItem.Item.__repr__` (as of zope 2.13 ).

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.

/reviewed-on nexedi/erp5!991
parent 76060d41
......@@ -385,3 +385,26 @@ return printed
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', '')
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 OFS.Image import File
from OFS.SimpleItem import Item
from Products.ERP5Type import _dtmldir
# Patch for displaying textearea in full window instead of
......@@ -11,3 +12,7 @@ File.manage = manage_editForm
File.manage_main = manage_editForm
File.manage_editDocument = 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 @@
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from OFS.Folder import Folder
from OFS.SimpleItem import Item
from Products.ERP5Type import Permissions
"""
......@@ -63,3 +64,7 @@ security = ClassSecurityInfo()
security.declareProtected(Permissions.ManagePortal, 'isERP5SitePresent')
Folder.security = security
InitializeClass(Folder)
# restore __repr__ after persistent > 4.4
# https://github.com/zopefoundation/Zope/issues/379
Folder.__repr__ = Item.__repr__
......@@ -3286,6 +3286,16 @@ return [
# but this did not affect the other role
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):
# Isolate test in a dedicaced class in order not to break other tests
# when this one fails.
......
......@@ -464,9 +464,9 @@ class Field:
InitializeClass(Field)
class ZMIField(
OFS.SimpleItem.Item,
Acquisition.Implicit,
Persistent,
OFS.SimpleItem.Item,
Field,
):
"""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