Commit c93d0b99 authored by Fabien Morin's avatar Fabien Morin

correct a bug that makes the default value of checkbox not working :

If a CheckBox has never been modified, the default value is 0. 
If you want the default value to be 1 (modifying the corresponding propertysheet), the DefaultValue method always return 0, even if 1 is in the propertysheet defined for the field (because of the condition "if value not in (None, ''); value = ob.getProperty(self.key, d=value)". So it was impossible to use the propertysheet to defined a default checked checkbox (the hack was to use tales).
With this new class, it's now possible to use propertysheet to have a checked default value on a CheckBox.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@25166 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent a88570e6
......@@ -212,6 +212,23 @@ class DefaultValue(StaticValue):
value = None
return self.returnValue(field, id, value)
class DefaultCheckBoxValue(DefaultValue):
def __call__(self, field, id, **kw):
try:
form = field.aq_parent
ob = getattr(form, 'aq_parent', None)
value = self.value
try:
value = ob.getProperty(self.key)
except Unauthorized:
value = ob.getProperty(self.key, d=value, checked_permission='View')
REQUEST = get_request()
if REQUEST is not None:
REQUEST.set('read_only_%s' % self.key, 1)
except (KeyError, AttributeError):
value = None
return self.returnValue(field, id, value)
class EditableValue(StaticValue):
def __call__(self, field, id, **kw):
......@@ -252,6 +269,10 @@ def getFieldValue(self, field, id, **kw):
field_id = field.id
if id == 'default' and field_id.startswith('my_'):
if field.meta_type == 'ProxyField' and \
field.getRecursiveTemplateField().meta_type == 'CheckBoxField' or \
self.meta_type == 'CheckBoxField':
return DefaultCheckBoxValue(field_id, value), cacheable
return DefaultValue(field_id, value), cacheable
# For the 'editable' value, we try to get a default value
......
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