def update(self): """See z3c.form.interfaces.IWidget.""" # Step 1: Determine the value. value = interfaces.NO_VALUE lookForDefault = False # Step 1.1: If possible, get a value from the request if not self.ignoreRequest: #at this turn we do not need errors to be set on widgets #errors will be set when extract gets called from form.extractData self.setErrors = False widget_value = self.extract() if widget_value is not interfaces.NO_VALUE: # Once we found the value in the request, it takes precendence # over everything and nothing else has to be done. self.value = widget_value value = PLACEHOLDER # Step 1.2: If we have a widget with a field and we have no value yet, # we have some more possible locations to get the value if (interfaces.IFieldWidget.providedBy(self) and value is interfaces.NO_VALUE and value is not PLACEHOLDER): # Step 1.2.1: If the widget knows about its context and the # context is to be used to extract a value, get # it now via a data manager. if (interfaces.IContextAware.providedBy(self) and not self.ignoreContext): value = zope.component.getMultiAdapter( (self.context, self.field), interfaces.IDataManager).query() # Step 1.2.2: If we still do not have a value, we can always use # the default value of the field, id set # NOTE: It should check field.default is not missing_value, but # that requires fixing zope.schema first if ((value is self.field.missing_value or value is interfaces.NO_VALUE) and self.field.default is not None): value = self.field.default lookForDefault = True # Step 1.3: If we still have not found a value, then we try to get it # from an attribute value if value is interfaces.NO_VALUE or lookForDefault: adapter = zope.component.queryMultiAdapter( (self.context, self.request, self.form, self.field, self), interfaces.IValue, name='default') if adapter: value = adapter.get() # Step 1.4: Convert the value to one that the widget can understand if value not in (interfaces.NO_VALUE, PLACEHOLDER): converter = interfaces.IDataConverter(self) self.value = converter.toWidgetValue(value) # Step 2: Update selected attributes for attrName in self._adapterValueAttributes: # only allow to set values for known attributes if hasattr(self, attrName): value = zope.component.queryMultiAdapter( (self.context, self.request, self.form, self.field, self), interfaces.IValue, name=attrName) if value is not None: setattr(self, attrName, value.get())
def update(self): value = zope.component.queryMultiAdapter( (self.context, self.request, self.widget, self.field, self.form, self.content), interfaces.IValue, name='message') if value is not None: self.message = value.get() else: self.message = self.createMessage()
def update(self): """See z3c.form.interfaces.IWidget.""" # Step 1: Determine the value. value = interfaces.NOVALUE lookForDefault = False # Step 1.1: If possible, get a value from the request if not self.ignoreRequest: widget_value = self.extract() if widget_value is not interfaces.NOVALUE: # Once we found the value in the request, it takes precendence # over everything and nothing else has to be done. self.value = widget_value value = PLACEHOLDER # Step 1.2: If we have a widget with a field and we have no value yet, # we have some more possible locations to get the value if (interfaces.IFieldWidget.providedBy(self) and value is interfaces.NOVALUE and value is not PLACEHOLDER): # Step 1.2.1: If the widget knows about its context and the # context is to be used to extract a value, get # it now via a data manager. if (interfaces.IContextAware.providedBy(self) and not self.ignoreContext and self.context is not None): value = zope.component.getMultiAdapter( (self.context, self.field), interfaces.IDataManager).get() # Step 1.2.2: If we still do not have a value, we can always use # the default value of the field, id set # NOTE: It should check field.default is not missing_value, but # that requires fixing zope.schema first if ((value is self.field.missing_value or value is interfaces.NOVALUE) and self.field.default is not None): value = self.field.default lookForDefault = True # Step 1.3: If we still have not found a value, then we try to get it # from an attribute value if value is interfaces.NOVALUE or lookForDefault: adapter = zope.component.queryMultiAdapter( (self.context, self.request, self.form, self.field, self), interfaces.IValue, name='default') if adapter: value = adapter.get() # Step 1.4: Convert the value to one that the widget can understand if value not in (interfaces.NOVALUE, PLACEHOLDER): converter = interfaces.IDataConverter(self) self.value = converter.toWidgetValue(value) # Step 2: Update selected attributes for attrName in self._adapterValueAttributes: value = zope.component.queryMultiAdapter( (self.context, self.request, self.form, self.field, self), interfaces.IValue, name=attrName) if value is not None: setattr(self, attrName, value.get())