[Zope3-Users] Re: zope.schema Question

Philipp von Weitershausen philipp at weitershausen.de
Mon Jul 7 03:56:28 EDT 2008


El 7 Jul 2008, a las 09:20 , Tim Cook escribió:
> On Mon, 2008-07-07 at 00:46 +0200, Philipp von Weitershausen wrote:
>
>>
>>   description=Object(
>>       schema=IFoo,
>>       ...
>>       )
>>
>> So the zope.schema.Object field is really about specifying objects  
>> that
>> provide a certain schema. It's not for *arbitrary* objects (use
>> zope.schema.Field or zope.interface.Attribute here).
>
> Thanks Philipp.
>
> Field doesn't work because it expects a unicode type.

I think you'll find that that's wrong. Field describes a generic  
attribute, much like z.i.Attribute.

> Attribute works but I would like to be able to flag it as 'required'
> which is not part of the Attribute class.

Right. Use Field for that :).

> Object would work if it would allow types that subclass from the  
> schema
> given.
>
> A concrete example:
>
> IItemStructure(Interface)
>   IItemTree(IItemStructure)
>   IItemTable(IItemStructure)
>   ...
>
> ItemTree(ItemStructure)
>  implements(IItemTree)
>
> ItemTable(ItemStructure)
>  implements(IItemTable)
>
> ...
>
> Now I want to allow description to be any descendant of ItemStructure.
> So I had hoped that:
>
>    description=Object(
>        schema=IItemStructure,
>        title=_(u"Description"),
>        description=_(u"Description of the activity."),
>        required=True,
>    )
>
> would provide that functionality.  It still throws a WrongTypeError.

The declaration looks ok. What throws a WrongTypeError where?

> I feel like the answer lies somewhere in the zope.interface.implement*
> functions but I lack the Zen to get the right combination.

It's hard to tell w/o knowing what actually throws the exception.



More information about the Zope3-users mailing list