Commit d3d2e100 authored by Romain Courteaud's avatar Romain Courteaud

GadgetField: allow to specify the validator form

This will improve the compatibility for all existing editorfield which will be migrated to gadgetfield (via proxy).
parent 1a176786
......@@ -5,6 +5,7 @@ from Products.Formulator import Validator
from zLOG import LOG, ERROR
from cStringIO import StringIO
from json import dumps
from Acquisition import aq_base
class GadgetWidget(Widget.Widget):
"""
......@@ -67,6 +68,7 @@ class GadgetFieldValidator(Validator.Validator):
property_names = Validator.Validator.property_names + [
'data_url',
'validator_form_id',
'validator_field_id'
]
......@@ -76,6 +78,15 @@ class GadgetFieldValidator(Validator.Validator):
"Checked if gadget return data url."),
default=0)
validator_form_id = fields.StringField(
'validator_form_id',
title='Validator Form ID',
description= "ID of the validator field's form. Default is the current form",
default="",
display_width=40,
required=0
)
validator_field_id = fields.StringField(
'validator_field_id',
title='Validator Field ID',
......@@ -93,11 +104,26 @@ class GadgetFieldValidator(Validator.Validator):
"""Get an external validator field located in the same form.
"""
field_id = field.id
validator_form_id = field.get_value('validator_form_id')
validator_field_id = field.get_value('validator_field_id')
if validator_field_id:
if field.aq_parent.has_field(validator_field_id,
validator_form = field.aq_parent
if (validator_form_id):
if '/' in validator_form_id:
portal = field.getPortalObject()
portal_skins = portal.portal_skins
# If a / is in the form_id, it means that skin_folder is explicitly
# defined. If so, prevent acquisition to get the form.
aq_validator_form = aq_base(portal_skins).unrestrictedTraverse(validator_form_id, None)
if aq_validator_form is not None:
validator_form = portal_skins.unrestrictedTraverse(validator_form_id)
else:
validator_form = getattr(validator_form, validator_form_id, None)
if (validator_form is not None) and validator_field_id:
if validator_form.has_field(validator_field_id,
include_disabled=1):
return field.aq_parent.get_field(validator_field_id,
return validator_form.get_field(validator_field_id,
include_disabled=1)
return None
......
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