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

ProxyField: make it possible to repair broken proxy fields

There have been a regression recently
parent b39b5e7b
Pipeline #24918 passed with stage
in 0 seconds
...@@ -398,9 +398,9 @@ return printed ...@@ -398,9 +398,9 @@ return printed
'Base_viewGeek', 'Base_viewGeek',
'View') 'View')
form = skin_folder._getOb('Base_viewGeek', None) form = skin_folder._getOb('Base_viewGeek', None)
form.manage_addField('my_title', 'Title', 'ProxyField') form.manage_addField('my_proxy_field', 'Proxy', 'ProxyField')
field = form.my_title field = form.my_proxy_field
self.assertFalse(form.get_fields()) self.assertFalse(form.get_fields())
self.assertEqual([field], form.get_fields(include_disabled=True)) self.assertEqual([field], form.get_fields(include_disabled=True))
...@@ -409,10 +409,22 @@ return printed ...@@ -409,10 +409,22 @@ return printed
self.assertEqual('', field.get_tales('default')) self.assertEqual('', field.get_tales('default'))
regexp = '^%s$' % re.escape("Can't find the template field of" regexp = '^%s$' % re.escape("Can't find the template field of"
" <ProxyField at /%s/portal_skins/erp5_geek/Base_viewGeek/my_title>" " <ProxyField at /%s/portal_skins/erp5_geek/Base_viewGeek/my_proxy_field>"
% self.portal.getId()) % self.portal.getId())
for func in ( field.render for func in ( field.render
, partial(field.get_value, 'default') , partial(field.get_value, 'default')
, partial(field.get_recursive_tales, 'default') , partial(field.get_recursive_tales, 'default')
): ):
self.assertRaisesRegexp(BrokenProxyField, regexp, func) self.assertRaisesRegexp(BrokenProxyField, regexp, func)
# we can still view the field in ZMI
form.manage_main()
field.manage_main()
# and repair it
form.manage_addField('my_field', 'Title', 'StringField')
field.manage_edit(
{
'field_form_id': 'Base_viewGeek',
'field_field_id': 'my_field',
})
self.assertEqual(field.getTemplateField(), form.my_field)
...@@ -171,8 +171,9 @@ class ProxyField(ZMIField): ...@@ -171,8 +171,9 @@ class ProxyField(ZMIField):
Surcharged values from proxied field. Surcharged values from proxied field.
""" """
# Edit template field attributes # Edit template field attributes
template_field = self.getRecursiveTemplateField() template_field = self.getTemplateField()
if template_field is not None: if template_field is not None:
template_field = self.getRecursiveTemplateField()
# Check the surcharged checkboxes # Check the surcharged checkboxes
surcharge_list = [] surcharge_list = []
...@@ -581,6 +582,14 @@ class ProxyField(ZMIField): ...@@ -581,6 +582,14 @@ class ProxyField(ZMIField):
# ("form_id and field_id don't define a valid template") # ("form_id and field_id don't define a valid template")
pass pass
security.declareProtected('View', 'title')
def title(self):
"""The title of this field."""
try:
return super(ProxyField, self).title()
except BrokenProxyField:
return 'broken'
security.declareProtected('Access contents information', 'has_value') security.declareProtected('Access contents information', 'has_value')
def has_value(self, id): def has_value(self, id):
""" """
......
...@@ -11,7 +11,7 @@ Surcharge <dtml-var meta_type> properties here. ...@@ -11,7 +11,7 @@ Surcharge <dtml-var meta_type> properties here.
<form action="manage_edit" method="POST"> <form action="manage_edit" method="POST">
<table cellspacing="0" cellpadding="2" border="0"> <table cellspacing="0" cellpadding="2" border="0">
<dtml-let proxy_field="this()" <dtml-let proxy_field="this()"
current_field="proxy_field.getRecursiveTemplateField()"> current_field="None if proxy_field.getTemplateField() is None else proxy_field.getRecursiveTemplateField()">
<!-- First, display ProxyField properties --> <!-- First, display ProxyField properties -->
<!-- see: Formulator/dtml/fieldEdit.dtml --> <!-- see: Formulator/dtml/fieldEdit.dtml -->
......
...@@ -68,7 +68,7 @@ This tab can therefore not be used. ...@@ -68,7 +68,7 @@ This tab can therefore not be used.
<!-- XXX Loop until find not a proxy field --> <!-- XXX Loop until find not a proxy field -->
<dtml-let proxy_field="this()" <dtml-let proxy_field="this()"
current_field="proxy_field.getRecursiveTemplateField()"> current_field="None if proxy_field.getTemplateField() is None else proxy_field.getRecursiveTemplateField()">
<dtml-if "current_field is not None"> <dtml-if "current_field is not None">
<dtml-let form="current_field.tales_form"> <dtml-let form="current_field.tales_form">
......
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