[Erp5-report] r25166 - /erp5/trunk/products/ERP5Form/Form.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Jan 19 12:04:32 CET 2009
Author: fabien
Date: Mon Jan 19 12:04:27 2009
New Revision: 25166
URL: http://svn.erp5.org?rev=25166&view=rev
Log:
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.
Modified:
erp5/trunk/products/ERP5Form/Form.py
Modified: erp5/trunk/products/ERP5Form/Form.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Form/Form.py?rev=25166&r1=25165&r2=25166&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Form/Form.py [utf8] (original)
+++ erp5/trunk/products/ERP5Form/Form.py [utf8] Mon Jan 19 12:04:27 2009
@@ -212,6 +212,23 @@
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 @@
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
More information about the Erp5-report
mailing list