Hi Frank,

> I need to send some data from a view class to all widgets that are
> used in the form. Unfortunately some of the widget that need to receive those
> data are contained e.g. in lists or dictionaries.
> I tried to do somthing like this:
>  request._data=somedata
> My view class would add 'somedata' to the request and all the widget would be 
> able
> to use it.
> But the the BrowserRequest doesn't like to be modified.

Right. Requests are read-only to the application.

> It there a chance to transport data throught the request object
> without modifying the depth of the zope core?
> Maybe there's a way for widgets to access the view class directly?

A typical solution is to push data to the widgets. IWidget (from
zope.app.form.interfaces) defines a 'setRenderedValue' method for
widgets that can be used to do that.

If you are using zope.formlib, you can also implement a custom
setUpWidgets method (documented in IFormBaseCustomization from
zope.formlib.interfaces). The default one for edit forms looks like this:

    def setUpWidgets(self, ignore_request=False):
        self.adapters = {}
        self.widgets = setUpEditWidgets(
            self.form_fields, self.prefix, self.context, self.request,
            adapters=self.adapters, ignore_request=ignore_request

setUpEditWidgets (defined in zope.formlib.form) will take the widget's
default values from self.context. For example, you could pass in
something other than that (perhaps an object holding the data you want
the widgets to present). You just have to make sure that it also
provides the interface that you're generating the form from.


Zope3-users mailing list

Reply via email to