Commit c4f60ee3 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

fixup! Formulator: prepare DateTimeField's sub_form dynamically.

parent 9ceca751
......@@ -493,10 +493,8 @@ class ProxyField(ZMIField):
field = template_field
return template_field
def _aq_dynamic(self, name):
if name == 'sub_form':
return self.getTemplateField().sub_form
return None
def _get_sub_form(self):
return self.getTemplateField()._get_sub_form(field=self)
security.declareProtected('Access contents information',
'is_delegated')
......
......@@ -764,15 +764,31 @@ class TestProxyField(ERP5TypeTestCase):
'my_date', 'Date', 'ProxyField')
proxy_field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary',
field_id='my_date',))
self.assertTrue(hasattr(proxy_field, 'sub_form'))
self.assertEqual(proxy_field.sub_form.render(),
original_field.sub_form.render())
self.assertTrue(hasattr(proxy_field, '_get_sub_form'))
self.assertEqual(proxy_field._get_sub_form().render(),
original_field._get_sub_form().render())
# we can render
proxy_field.render()
# and validate
self.container.Base_view.validate_all_to_request(self.portal.REQUEST)
# change style in the original field
original_field.manage_edit_xmlrpc(dict(input_style='number'))
self.assertTrue('type="number"' in original_field.render())
self.assertTrue('type="number"' in proxy_field.render())
# override style in the proxy field
original_field.manage_edit_xmlrpc(dict(input_style='text'))
proxy_field._surcharged_edit({'input_style': 'number'}, ['input_style'])
self.assertTrue('type="text"' in original_field.render())
self.assertTrue('type="number"' in proxy_field.render())
# unproxify the proxy field
self.container.Base_view.unProxifyField({'my_date': 'on'})
unproxified_field = self.container.Base_view.my_date
self.assertTrue('type="number"' in unproxified_field.render())
def test_manage_edit_surcharged_xmlrpc(self):
# manage_edit_surcharged_xmlrpc is a method to edit proxyfields
# programmatically
......@@ -943,7 +959,7 @@ class TestFieldValueCache(ERP5TypeTestCase):
addField(DateTimeField('datetime_field'))
form.datetime_field._p_oid = makeDummyOid()
form.datetime_field._edit(dict(input_style='list'))
for i in form.datetime_field.sub_form.fields.values():
for i in form.datetime_field._get_sub_form().fields.values():
i._p_oid = makeDummyOid()
def test_method_field(self):
......
......@@ -403,7 +403,7 @@ class Field:
a form. Works like render() but for sub field.
Added key parameter for ERP5 in order to be compatible with listbox/matrixbox
"""
return self.sub_form.get_field(id)._render_helper(
return self._get_sub_form().get_field(id)._render_helper(
self.generate_subfield_key(id, key=key), value, REQUEST, render_prefix)
security.declareProtected('View', 'render_sub_field_from_request')
......@@ -411,7 +411,7 @@ class Field:
"""Convenience method; render the field widget from REQUEST
(unvalidated data), or default if no raw data is found.
"""
return self.sub_form.get_field(id)._render_helper(
return self._get_sub_form().get_field(id)._render_helper(
self.generate_subfield_key(id), None, REQUEST)
security.declarePrivate('_validate_helper')
......@@ -441,7 +441,7 @@ class Field:
def validate_sub_field(self, id, REQUEST, key=None):
"""Validates a subfield (as part of field validation).
"""
return self.sub_form.get_field(id)._validate_helper(
return self._get_sub_form().get_field(id)._validate_helper(
self.generate_subfield_key(id, validation=1, key=key), REQUEST)
def PrincipiaSearchSource(self):
......
......@@ -127,9 +127,10 @@ class DateTimeField(ZMIField):
widget = Widget.DateTimeWidgetInstance
validator = Validator.DateTimeValidatorInstance
@property
def sub_form(self):
input_style = self.get_value('input_style')
def _get_sub_form(self, field=None):
if field is None:
field = self
input_style = field.get_value('input_style')
if input_style == 'text':
return create_datetime_text_sub_form(self)
elif input_style == 'list':
......
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