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


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:

        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__',

Marius Gedminas
* philiKON wonders what niemeyer is committing :)
*** benji_york is now known as benji
<benji> murder?
                -- #zope3-dev

Attachment: signature.asc
Description: Digital signature

Zope3-users mailing list

Reply via email to