Hi, I have here an add form which is based on an interface like this:
value1 = TextLine()
value2 = TextLine()
In my add form, I need to display a default value for "value2". This default
value is stored in another object, however, no default value should be given
I'm desperatingly trying to implement this via z3c.form through various ways,
but none seems to work. I had a look at "widget.py", line 73 (the update
method where the value is retrieved) and found the following:
1.1) From Request: I could solve my problem like the following in my update()
self.request.form['form.widgets.value2'] = 'mydefault'
However, I don't think it's a nice solution to modify the request for a
1.2.1) Via a datamanger: Seems to be not possible as I can't explicitly
set "ignoreContext = False" for a single widget. Therefore this fails as I
don't have a datamanager for value1. Moreover it seems the datamanger is not
a named adapter:
value = zope.component.getMultiAdapter(
(self.context, self.field), interfaces.IDataManager).get()
Therefore in my case, where value1/value2 are both TextLines and have the same
widget, it's not possible to register the datamanager for value2 only.
1.2.2) Via the field default value: Maybe possible by cloning the field in the
update() method of my form and setting a default value there, however, this
looks lie a _very_ bad style to me.
1.3) From an object attribute (don't really understand what this Step is for):
Seems also not possible as there's once again no way to register a named
adapter here and therefore the absence of "value1" as object attribute will
lead to an error:
adapter = zope.component.queryMultiAdapter(
(self.context, self.request, self.form, self.field, self),
So, either I missed somehow a good solution, or my pattern is not addressed in
z3c.form. In this case, I'd suggest to handle this case in two ways:
1) Add e.g. Step 1.2.3, which queries after a named adapter where the name is
the field name. This way, I'd be able to register an adapter that retrieves
the default value from somewhere else.
2) Provide a way to tell single widgets (and not only the widget manager) to
ignore/not ignore the context. This way, I could simply use the getContent()
method in my view, although there's once again the same problem if the
default values don't come from a single object (as my getContent routine
cannot decide which object to return).
I don't know if these two solutions would conflict with other parts of the
framework, maybe there's an even better solution?
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7
Zope3-users mailing list