Add "force_store_value" property. If set, store, for example, calculated value as owner values.

So calculated value are calculate only one time.
This commit is contained in:
Emmanuel Garette 2013-04-16 09:45:42 +02:00
parent 1f0bb88bc1
commit 447c175b6a
1 changed files with 5 additions and 2 deletions

View File

@ -146,6 +146,9 @@ class Values(object):
if validate and not opt.validate(value, self.context, setting.has_property('validator')): if validate and not opt.validate(value, self.context, setting.has_property('validator')):
raise ValueError(_('invalid calculated value returned' raise ValueError(_('invalid calculated value returned'
' for option {0}: {1}').format(opt._name, value)) ' for option {0}: {1}').format(opt._name, value))
if self.is_default_owner(opt) and \
setting.has_property('auto_store_value', opt, False):
self.setitem(opt, value)
return value return value
def __setitem__(self, opt, value): def __setitem__(self, opt, value):
@ -245,8 +248,8 @@ class Multi(list):
def _validate(self, value): def _validate(self, value):
if value is not None and not self.opt._validate(value): if value is not None and not self.opt._validate(value):
raise ValueError(_("invalid value {0} " raise ValueError(_("invalid value {0} "
"for option {1}").format(str(value), "for option {1}").format(str(value),
self.opt._name)) self.opt._name))
def pop(self, key, force=False): def pop(self, key, force=False):
"""the list value can be updated (poped) """the list value can be updated (poped)