[Zope3-Users] Error when calling addform
Marius Gedminas
mgedmin at b4net.lt
Sun Feb 11 17:17:55 EST 2007
On Sun, Feb 11, 2007 at 07:26:21PM +0100, Florian Lindner wrote:
> Hello,
> I have an addform registered:
>
> <addform
> label="Add Blog Comment"
> name="AddBlogComment.html"
> schema="..interfaces.IBlogComment"
> content_factory="..blog.BlogComment"
> permission="Blog.AddComment"
> />
>
> class IBlogComment(IContained):
> containers(IBlogEntry)
>
> name = TextLine(
> title = u"Your name",
> description = u"Your name or nickname",
> default = u"Guest",
> required = True)
>
> email = TextLine(
> title = u"E-Mail",
> required = False)
>
> content = Text(
> title = u"Blog comment content",
> default = u"",
> required = True)
>
>
> but when I call the addform resp. click on the addMenuItem I get an system
> error:
...
> ComponentLookupError: ((<zope.schema._bootstrapfields.Field object at
> 0x9e95b2c>, <zope.publisher.browser.BrowserRequest instance
> URL=http://localhost:8080/xgm/Blog/2007_02_10_erster_post/+/AddBlogComment.html>),
> <InterfaceClass zope.app.form.interfaces.IInputWidget>, u'')
>
> .... what do I have misconfigured here?
You have
containers(IBlogEntry)
in your schema. That's equivalent to
__parent__ = Field(constraint=ContainerTypesConstraint(IBlogEntry))
Your add form is trying to find a widget suitable for Field, but there
isn't one.
Note also that you will inherit
__name__ = TextLine(...)
from IContained. I do not think you want __name__ and __parent__ in
your add form. To skip those fields you'll have to explicitly enumerate
all the other fields:
<addform
...
schema="..interfaces.IBlogComment"
fields="name email content"
...
/>
Alternative solution: split the schema into a separate interface,
specify it in the <addform> directive, then define an interface for your
content object that inherits IContained, your schema, and specifies the
container constraint. It's probably not worth bothering, given that you
need to enumerate only three fields.
An even better solution: learn zope.formlib and use it. Much better
than the bare standard forms. Here's a very short example of an add
form with zope.formlib: http://mg.pov.lt/blog/formlib-adding
I'll copy a part of it here:
class FruitAdd(form.AddForm):
form_fields = form.Fields(IFruit)
Now if you want to omit some fields from the schema, like in your
example above, you can do
class BlogCommentAdd(form.AddForm):
form_fields = form.Fields(IBlogComment).omit('__name__',
'__parent__')
Marius Gedminas
--
* philiKON wonders what niemeyer is committing :)
*** benji_york is now known as benji
<benji> murder?
-- #zope3-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.zope.org/pipermail/zope3-users/attachments/20070212/0f478fc1/attachment.bin
More information about the Zope3-users
mailing list