[Zope3-Users] "Wrong contained type" - why?

Rupert Redington rupert at neontribe.co.uk
Thu Apr 26 12:50:56 EDT 2007


Hermann Himmelbauer wrote:
> Hi,
> As already mentioned before, I use interfaces that contain lists of other 
> interfaces via the following syntax:
> 
> emails = List(value_type=Object(schema=IEmail))
> 
> In my formlib-based class, I have use the following, so that the widgets are 
> displayed correctly:
> 
> email_widget = CustomWidgetFactory(ObjectWidget,Email)
> emails_widget = CustomWidgetFactory(ListSequenceWidget, 
> subwidget=email_widget)
> 
> and in the form.Form based class:
> 
> form_fields['emails'].custom_widget = emails_widget
> 
> The widgets are displayed perfectly, but when I try to update the data, the 
> validation fails with the following error:
> 
> "Wrong contained type"
> 
> I don't know how to get around this, especially I don't find a good entry 
> point to this problem - it seems that this error comes from the 
> widget.getInputValue() function - is that true?
> 
> All objects in my example are of the type Interface, perhaps I have to define 
> them as containers? 
> 
> Another thing I don't know is how I can omit fields from the email_widget, is 
> there a simple solution?
> 
> Best Regards,
> Hermann
> 

Hi Guys,

Curiously I seem to have run into a similar problem to Hermann's at
about the same time...

I too am using a Custom ObjectWidget in a ListSequenceWidget:

viewassociation_widget = CustomWidgetFactory(ObjectWidget, ViewAssociation)
elements_widget = CustomWidgetFactory(ListSequenceWidget,
subwidget=viewassociation_widget)

and placing it into my formlib.EditForm :

form_fields['elements'].custom_widget = elements_widget


The fields in the ObjectWidget are drawn from IViewAssociation :

class IViewAssociation(Interface):
    """Stores information about an editor's choice of view
       for an item within a section
    """

    viewtype = Choice(
        title=_(u"View Type"),
        description=_(u"A type for the view"),
        required = True,
        values = [u'insert', u'thumbnail', u'link']
        )

    item = Choice(
        title=_(u"Content Item"),
        description=_(u"The item providing data for this view element"),
        required = True,
        vocabulary = u'Clipboard',
        )

    section = Attribute(u'The Section Object using this Association')


The form renders correctly, which is nice, but only validates and
creates and add the ViewAssociation objects if I knock out the 'item' field.

When I include the 'item' field in the schema validation fails with
"Wrong contained type". Here's the current simplified testing version of
the "Clipboard" vocabulary.

session = z3c.zalchemy.getSession
class ClipboardVocabFactory(object):
    implements(IVocabularyFactory)

    def __call__(self, context):
        items = [x for x in session().query(ArchiveObject).select()]
        voc = SimpleVocabulary.fromValues(items)
        return voc


ViewAssociation objects can accept ArchiveObjects in their item
attribute in my unit tests...

To (spookily) increase the similarity of my case to Hermann's I too
would like to control the subwidgets in the Custom ObjectWidget - in my
case by using a RadioWidget for the viewtype field - but I can't quite
work out how.

viewassociation_widget = CustomWidgetFactory(ObjectWidget,
ViewAssociation, viewtype_widget=RadioWidget)

raises:

TypeError: Unable to configure a widget for viewtype - attribute
viewtype_widget does not implement IWidget

Thanks for fighting through this overlong post.
Can anyone help?

Rupert


More information about the Zope3-users mailing list