[Grok-dev] schema.Object

Uli Fouquet uli at gnufix.de
Wed Jul 21 09:20:14 EDT 2010


Hi there,

Sascha Boch wrote:
> Ok, still no joy. The form is rendered fine but the "Fields: Object is
> of wrong type." keeps coming. Here's the code:
> 
> class IFooField(interface.Interface):
>     name = schema.TextLine(title=u'Name', required = True)
>     label = schema.TextLine(title=u'Label', required = True)
>     format = schema.Choice(title=u'Field Format', required = True,
> values = ['Text', 'Date', 'Number'])
> 
> class FooField(grok.Model):
>     grok.implements(IFooField)
>     name = FieldProperty(IFooField['name'])
>     label = FieldProperty(IFooField['label'])
>     format = FieldProperty(IFooField['format'])
>    
> class IFoo(interface.Interface):
>     title=schema.TextLine(title=u'Title',required=True)
>     description=schema.TextLine(title=u'Description',required=False)
>     data_fields_ext = schema.List(title=u'Fields', required = False,
> unique = True, 
>         value_type = schema.Object(title=u'Field', required = False,
> schema = IFooField))
>     
> class Foo(grok.Application, grok.Container):
>     grok.implements(IFoo)
>     title = u'Foobar'
>     description = u''
>     
> class FooEditForm(grok.EditForm):
>     grok.context(Foo)
>     grok.name('admin')
>     
>     form_fields = grok.AutoFields(Foo) 
>     object_widget = CustomWidgetFactory(ObjectWidget, FooField)
>     form_fields['data_fields_ext'].custom_widget =
> CustomWidgetFactory(SequenceWidget, subwidget=object_widget)
>     template = grok.PageTemplateFile('custom_edit_form.pt') 

At a quick glance: your Foo has no `data_fields_ext` attribute, although
it is promised to exist in IFoo.

This makes me think (as you're also using a grok.Container for Foo),
that you don't want the subentries as attributes
(foo_instance.data_fields_ext[0].format), but as items in the container
(foo_instance['somename'].format). In that case you could do the whole
thing completely different and without IObject.

Then, you try to render a list using a SequenceWidget. Shouldn't that be
ListSequenceWidget? The SequenceWidget expects a tuple and not a list if
IIRC.

Best regards,

-- 
Uli


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.zope.org/pipermail/grok-dev/attachments/20100721/02c7a9c8/attachment.bin 


More information about the Grok-dev mailing list