[Zope3-dev] formlib addForm
Christian Lueck
christian.lueck at ruhr-uni-bochum.de
Sun Sep 25 15:58:04 EDT 2005
Hi,
I want to write a customized add-view with formlib. I've written an
addview-class with a 'create' method (see below) and a custom-factory
which is called by the create method. The problem I got stuck with now
is a problem of context and instantiation and I guess maybe the solution
would be a different registration of the view.
The view is for adding new 'Example' objects to an 'ExampleDB'
container-object.
I have registered the page with the <browser:page> directive -- I don't
know if this is right at all:
<page
name="AddExample.html"
for="paradigm.paradigmdb.interfaces.IExample"
class=".example.ExampleAddView"
permission="zope.ManageContent"
/>
I 've tried two alternative values for the 'for'-attribute: 1) the
container-object interface, 2) the interface for the object to be added
(see above).
ad 1) The page is rendered, but when I press the Add-button there's an
error: After the 'createAndAdd'-method (inherited from
formlib.form.AddFormBase) has called my customized 'create'-method it
calls an 'add'-method, which calls self.context.add(...), but there is
no 'add'-method for my ExampleDB-object (which is the context). Should
there be one???
ad 2) This alternative seems to be better, since I want to add
'Example'-objects. But there is no 'Example'-object at the time when the
view is called. So what is the context?
The solution will be, as I guess, very similar to the z3-form-framework
with its /containerX/+/AddObjectY.html thing. I've studied the
source-code of zope.app.form.browser.add.AddView but run out of
comprehension..
zope.app.container.interfaces.IAdding seems most promising -- but what
to do with it?
Question:
Is it right to register a formlib-based addview with the
<browser:page>-directive?
How do I get the + ? ;)
Kind regards,
Christian
The view-class:
import <snip>
class ExampleAddView(ExampleMisc, MyFormlibForm, form.AddForm):
form_fields = form.Fields(IExample['example_orig_lang'],
IExampleResourceSet)
template = ViewPageTemplateFile('example_add.pt')
def create(self, data):
example_factory = zapi.getUtility(IFactory,
u"example.ExampleFactory_AddForm")
example = example_factory(
einheitsacht = self.request.get('einheitsacht', None),
resource = self.request.get('resource', None),
example_orig_lang = data['example_orig_lang'],
example_x_lang = [],
example_in_resource_lang = data['example_in_resource_lang'],
quotation = data['quotation'],
page = data['page'])
return example
def renderFormExample_orig_lang(self):
return MyFormlibRenderField(self.widgets['example_orig_lang'],
self.request)()
def renderFormExample_in_resource_lang(self):
return
MyFormlibRenderField(self.widgets['example_in_resource_lang'],
self.request)()
<snip>
More information about the Zope3-dev
mailing list