[Zope3-dev] ILocation, Location and ObjectField problem

Dominik Huber dominik.huber at projekt01.ch
Wed May 26 13:37:26 EDT 2004


Today I run accross the following problem while using Location,
ILocation and ObjectField:

Problem setup::

    >>> from zope.interface import implements, Interface
    >>> from zope.schema import Object
    >>> from zope.schema.fieldproperty import FieldProperty
    >>> from zope.app.location.interfaces import ILocation
    >>> from zope.app.location.location import Location

    >>> class IA(Interface):
    ...     location = Object(schema=ILocation, required=False,
default=None)
    ...
    >>> class A(object):
    ...     location = FieldProperty(IA['location'])

Problem example::

    >>> a = A()
    >>> location = Location()
    >>> a.location = location
    Traceback (most recent call last):
    ...
    WrongContainedType: []

Error *RequiredMissing*::

    >>> try:
    ...     a.location = location
    ... except Exception, e:
    ...     print e.args[0][0].__class__
    zope.schema._bootstrapinterfaces.RequiredMissing


Possible Solutions
------------------

1. change ILocation interface
2. change Location implementation
3. status quo

I would choose 1. Other opinions?

regards,
dominik


Suggested change for 1::

class ILocation(Interface):
    """Objects that have a structural location"""

    __parent__ = Attribute("The parent in the location hierarchy")

    __name__ = schema.TextLine(
        title=u"The name within the parent",
        description=u"Parent can be traversed with this name to get the
object.",
        required=False,
        default=None)





More information about the Zope3-dev mailing list