[Checkins] SVN: z3c.relationfieldui/trunk/src/z3c/relationfieldui/ Cut out everything but the widget stuff.
Martijn Faassen
faassen at infrae.com
Fri Oct 17 11:58:35 EDT 2008
Log message for revision 92315:
Cut out everything but the widget stuff.
Changed:
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/__init__.py
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml
D z3c.relationfieldui/trunk/src/z3c/relationfieldui/event.py
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftesting.zcml
D z3c.relationfieldui/trunk/src/z3c/relationfieldui/index.py
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/interfaces.py
D z3c.relationfieldui/trunk/src/z3c/relationfieldui/relation.py
D z3c.relationfieldui/trunk/src/z3c/relationfieldui/schema.py
U z3c.relationfieldui/trunk/src/z3c/relationfieldui/testing.py
-=-
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/README.txt 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,153 +1,42 @@
-========
-Relation
-========
+===================
+z3c.relationfieldui
+===================
-This package implements a new schema field Relation, a widget for
-relations, and the Relation objects that store actual relations. In
-addition it can index these relations using the ``zc.relation``
-infractructure, and therefore efficiently answer questions about the
-relations.
+This package implements a widget for relations as defined by
+`z3c.relationfield`_.
-The Relation field
-------------------
+.. `_z3c.relationfield`: http://pypy.python.org/pypi/z3c.relationfield
-First, some bookkeeping that can go away as soon as we release a fixed
-Grok. We first need to grok ftests to make sure we have the right
-utilities registered::
+Setup
+-----
- >>> import grok
- >>> grok.testing.grok('z3c.relationfield.ftests')
+In order to demonstrate our widget, we need to set up a relation field.
-We previously defined an interface ``IItem`` with a relation field in
-it. We also defined a class ``Item`` that implements both ``IItem``
-and the special ``z3c.relationfield.interfaces.IHasRelations``
-interface. The ``IHasRelation`` marker interface is needed to let the
-relations be cataloged. Unfortunately we cannot define ``Item`` and
-``IItem`` in the doctest here, as these objects need to be stored in
-the ZODB cleanly and therefore need to be in a module. Let's set up a
-test application in a container::
+We first need to grok ftests to make sure we have the right utilities
+registered::
- >>> root = getRootFolder()['root'] = TestApp()
+ >>> import grok
+ >>> grok.testing.grok('z3c.relationfieldui.ftests')
-We make sure that this is the current site, so we can look up local
-utilities in it and so on::
+Let's set up a test application with content in it, including a relation
+from ``b`` to ``a``::
+ >>> root = getRootFolder()['root'] = TestApp()
>>> from zope.app.component.hooks import setSite
>>> setSite(root)
-
-We'll add an item ``a`` to it::
-
>>> root['a'] = Item()
-
-All items, including the one we just created, should have unique int
-ids as this is required to link to them::
-
+ >>> from z3c.relationfield import RelationValue
+ >>> b = Item()
>>> from zope import component
>>> from zope.app.intid.interfaces import IIntIds
>>> intids = component.getUtility(IIntIds)
>>> a_id = intids.getId(root['a'])
- >>> a_id >= 0
- True
-
-The relation is currently ``None``::
-
- >>> root['a'].rel is None
- True
-
-Now we can create an item ``b`` that links to item ``a``::
-
- >>> from z3c.relationfield import RelationValue
- >>> b = Item()
>>> b.rel = RelationValue(a_id)
-
-We now store the ``b`` object, which will also set up its relation::
-
>>> root['b'] = b
-Let's examine the relation. First we'll check which attribute of the
-pointing object ('b') this relation is pointing from::
+We also need to set up a utility that knows how to generate an object
+path for a given object, and back::
- >>> root['b'].rel.from_attribute
- 'rel'
-
-We can ask for the object it is pointing at::
-
- >>> to_object = root['b'].rel.to_object
- >>> to_object.__name__
- u'a'
-
-We can also get the object that is doing the pointing; since we
-supplied the ``IHasRelations`` interface, the event system took care
-of setting this::
-
- >>> from_object = root['b'].rel.from_object
- >>> from_object.__name__
- u'b'
-
-This object is also known as the ``__parent__``; again the event
-sytem took care of setting this::
-
- >>> parent_object = root['b'].rel.__parent__
- >>> parent_object is from_object
- True
-
-The relation also knows about the interfaces of both the pointing object
-and the object that is being pointed at::
-
- >>> sorted(root['b'].rel.from_interfaces)
- [<InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>,
- <InterfaceClass zope.app.container.interfaces.IContained>,
- <InterfaceClass grokcore.component.interfaces.IContext>,
- <InterfaceClass z3c.relationfield.interfaces.IHasRelations>,
- <InterfaceClass z3c.relationfield.ftests.IItem>,
- <InterfaceClass persistent.interfaces.IPersistent>]
-
- >>> sorted(root['b'].rel.to_interfaces)
- [<InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>,
- <InterfaceClass zope.app.container.interfaces.IContained>,
- <InterfaceClass grokcore.component.interfaces.IContext>,
- <InterfaceClass z3c.relationfield.interfaces.IHasRelations>,
- <InterfaceClass z3c.relationfield.ftests.IItem>,
- <InterfaceClass persistent.interfaces.IPersistent>]
-
-We can also get the interfaces in flattened form::
-
- >>> sorted(root['b'].rel.from_interfaces_flattened)
- [<InterfaceClass zope.annotation.interfaces.IAnnotatable>,
- <InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>,
- <InterfaceClass zope.app.container.interfaces.IContained>,
- <InterfaceClass grokcore.component.interfaces.IContext>,
- <InterfaceClass z3c.relationfield.interfaces.IHasRelations>,
- <InterfaceClass z3c.relationfield.ftests.IItem>,
- <InterfaceClass zope.location.interfaces.ILocation>,
- <InterfaceClass persistent.interfaces.IPersistent>,
- <InterfaceClass zope.interface.Interface>]
- >>> sorted(root['b'].rel.to_interfaces_flattened)
- [<InterfaceClass zope.annotation.interfaces.IAnnotatable>,
- <InterfaceClass zope.annotation.interfaces.IAttributeAnnotatable>,
- <InterfaceClass zope.app.container.interfaces.IContained>,
- <InterfaceClass grokcore.component.interfaces.IContext>,
- <InterfaceClass z3c.relationfield.interfaces.IHasRelations>,
- <InterfaceClass z3c.relationfield.ftests.IItem>,
- <InterfaceClass zope.location.interfaces.ILocation>,
- <InterfaceClass persistent.interfaces.IPersistent>,
- <InterfaceClass zope.interface.Interface>]
-
-Paths
------
-
-We can also obtain the path of the relation (both from where it is
-pointing as well as to where it is pointing). The path should be a
-human-readable reference to the object we are pointing at, suitable
-for serialization. In order to work with paths, we first need to set
-up an ``IObjectPath`` utility.
-
-Since in this example we only place objects into a single flat root
-container, the paths in this demonstration can be extremely simple:
-just the name of the object we point to. In more sophisticated
-applications a path would typically be a slash separated path, like
-``/foo/bar``::
-
>>> from z3c.objpath.interfaces import IObjectPath
>>> class ObjectPath(grok.GlobalUtility):
... grok.provides(IObjectPath)
@@ -159,224 +48,6 @@
>>> grok.testing.grok_component('ObjectPath', ObjectPath)
True
-After this, we can get the path of the object the relation points to::
-
- >>> root['b'].rel.to_path
- u'a'
-
-We can also get the path of the object that is doing the pointing::
-
- >>> root['b'].rel.from_path
- u'b'
-
-Relation queries
-----------------
-
-Now that we have set up and indexed a relationship between ``a`` and
-``b``, we can issue queries using the relation catalog. Let's first
-get the catalog::
-
- >>> from zc.relation.interfaces import ICatalog
- >>> catalog = component.getUtility(ICatalog)
-
-Let's ask the catalog about the relation from ``b`` to ``a``::
-
- >>> l = sorted(catalog.findRelations({'to_id': intids.getId(root['a'])}))
- >>> l
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-We look at this relation object again. We indeed go the right one::
-
- >>> rel = l[0]
- >>> rel.from_object.__name__
- u'b'
- >>> rel.to_object.__name__
- u'a'
- >>> rel.from_path
- u'b'
- >>> rel.to_path
- u'a'
-
-Asking for relations to ``b`` will result in an empty list, as no such
-relations have been set up::
-
- >>> sorted(catalog.findRelations({'to_id': intids.getId(root['b'])}))
- []
-
-We can also issue more specific queries, restricting it on the
-attribute used for the relation field and the interfaces provided by
-the related objects. Here we look for all relations between ``b`` and
-``a`` that are stored in object attribute ``rel`` and are pointing
-from an object with interface ``IItem`` to another object with the
-interface ``IItem``::
-
- >>> sorted(catalog.findRelations({
- ... 'to_id': intids.getId(root['a']),
- ... 'from_attribute': 'rel',
- ... 'from_interfaces_flattened': IItem,
- ... 'to_interfaces_flattened': IItem}))
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-There are no relations stored for another attribute::
-
- >>> sorted(catalog.findRelations({
- ... 'to_id': intids.getId(root['a']),
- ... 'from_attribute': 'foo'}))
- []
-
-There are also no relations stored for a new interface we'll introduce
-here::
-
- >>> class IFoo(IItem):
- ... pass
-
- >>> sorted(catalog.findRelations({
- ... 'to_id': intids.getId(root['a']),
- ... 'from_interfaces_flattened': IItem,
- ... 'to_interfaces_flattened': IFoo}))
- []
-
-Changing the relation
----------------------
-
-Let's create a new object ``c``::
-
- >>> root['c'] = Item()
- >>> c_id = intids.getId(root['c'])
-
-Nothing points to ``c`` yet::
-
- >>> sorted(catalog.findRelations({'to_id': c_id}))
- []
-
-We currently have a relation from ``b`` to ``a``::
-
- >>> sorted(catalog.findRelations({'to_id': intids.getId(root['a'])}))
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-We can change the relation to point at a new object ``c``::
-
- >>> root['b'].rel = RelationValue(c_id)
-
-We need to send an ``IObjectModifiedEvent`` to let the catalog know we
-have changed the relations::
-
- >>> from zope.event import notify
- >>> notify(grok.ObjectModifiedEvent(root['b']))
-
-We should find now a single relation from ``b`` to ``c``::
-
- >>> sorted(catalog.findRelations({'to_id': c_id}))
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-The relation to ``a`` should now be gone::
-
- >>> sorted(catalog.findRelations({'to_id': intids.getId(root['a'])}))
- []
-
-Removing the relation
----------------------
-
-We have a relation from ``b`` to ``c`` right now::
-
- >>> sorted(catalog.findRelations({'to_id': c_id}))
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-We can clean up an existing relation from ``b`` to ``c`` by setting it
-to ``None``::
-
- >>> root['b'].rel = None
-
-We need to send an ``IObjectModifiedEvent`` to let the catalog know we
-have changed the relations::
-
- >>> notify(grok.ObjectModifiedEvent(root['b']))
-
-Setting the relation on ``b`` to ``None`` should remove that relation
-from the relation catalog, so we shouldn't be able to find it anymore::
-
- >>> sorted(catalog.findRelations({'to_id': intids.getId(root['c'])}))
- []
-
-Let's reestablish the removed relation::
-
- >>> root['b'].rel = RelationValue(c_id)
- >>> notify(grok.ObjectModifiedEvent(root['b']))
-
- >>> sorted(catalog.findRelations({'to_id': c_id}))
- [<z3c.relationfield.relation.RelationValue object at ...>]
-
-Copying an object with relations
---------------------------------
-
-Let's copy an object with relations::
-
- >>> from zope.copypastemove.interfaces import IObjectCopier
- >>> IObjectCopier(root['b']).copyTo(root)
- u'b-2'
- >>> u'b-2' in root
- True
-
-Two relations to ``c`` can now be found, one from the original, and
-the other from the copy::
-
- >>> l = sorted(catalog.findRelations({'to_id': c_id}))
- >>> len(l)
- 2
- >>> l[0].from_path
- u'b'
- >>> l[1].from_path
- u'b-2'
-
-Removing an object with relations
----------------------------------
-
-We will remove ``b-2`` again. Its relation should automatically be removed
-from the catalog::
-
- >>> del root['b-2']
- >>> l = sorted(catalog.findRelations({'to_id': c_id}))
- >>> len(l)
- 1
- >>> l[0].from_path
- u'b'
-
-Temporary relations
--------------------
-
-If we have an import procedure where we import relations from some
-external source such as an XML file, it may be that we read a relation
-that points to an object that does not yet exist as it is yet to be
-imported. We provide a special ``TemporaryRelationValue`` for this
-case. A ``TemporaryRelationValue`` just contains the path of what it
-is pointing to, but does not resolve it yet. Let's use
-``TemporaryRelationValue`` in a new object, creating a relation to
-``a``::
-
- >>> from z3c.relationfield import TemporaryRelationValue
- >>> root['d'] = Item()
- >>> root['d'].rel = TemporaryRelationValue('a')
-
-A modification event does not actually get this relation cataloged::
-
- >>> before = sorted(catalog.findRelations({'to_id': a_id}))
- >>> notify(grok.ObjectModifiedEvent(root['d']))
- >>> after = sorted(catalog.findRelations({'to_id': a_id}))
- >>> len(before) == len(after)
- True
-
-We will now convert all temporary relations on ``d`` to real ones::
-
- >>> from z3c.relationfield import realize_relations
- >>> realize_relations(root['d'])
- >>> notify(grok.ObjectModifiedEvent(root['d']))
-
-The relation will now show up in the catalog::
-
- >>> after2 = sorted(catalog.findRelations({'to_id': a_id}))
- >>> len(after2) > len(before)
- True
-
The relation widget
-------------------
@@ -408,7 +79,7 @@
Let's take a look at the relation widget now::
>>> from zope.publisher.browser import TestRequest
- >>> from z3c.relationfield import RelationWidget
+ >>> from z3c.relationfieldui import RelationWidget
>>> request = TestRequest()
>>> widget = RelationWidget(IItem['rel'], request)
>>> print widget()
@@ -422,12 +93,12 @@
on the object called "relationurl". Without such a view, the display
widget will link directly to the object::
- >>> from z3c.relationfield import RelationDisplayWidget
+ >>> from z3c.relationfieldui import RelationDisplayWidget
>>> widget = RelationDisplayWidget(IItem['rel'], request)
We have to set the widget up with some data::
- >>> widget._data = rel
+ >>> widget._data = b.rel
The widget will point to the plain URL of ``rel``'s ``to_object``::
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/__init__.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/__init__.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/__init__.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,5 +1 @@
-from z3c.relationfield.relation import RelationValue, TemporaryRelationValue
-from z3c.relationfield.index import RelationCatalog
-from z3c.relationfield.schema import Relation
-from z3c.relationfield.event import realize_relations
-from z3c.relationfield.widget import RelationWidget, RelationDisplayWidget
+from z3c.relationfieldui.widget import RelationWidget, RelationDisplayWidget
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/configure.zcml 2008-10-17 15:58:34 UTC (rev 92315)
@@ -4,6 +4,7 @@
<include package="grok" file="meta.zcml" />
<include package="grok" />
+ <include package="z3c.relationfield" />
<grok:grok package="."/>
Deleted: z3c.relationfieldui/trunk/src/z3c/relationfieldui/event.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/event.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/event.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,100 +0,0 @@
-import grokcore.component as grok
-
-from zope.interface import providedBy
-from zope.schema import getFields
-from zope import component
-from zope.app.intid.interfaces import IIntIds
-from zope.app.container.interfaces import (IObjectAddedEvent,
- IObjectRemovedEvent)
-from zope.lifecycleevent.interfaces import IObjectModifiedEvent
-
-from zc.relation.interfaces import ICatalog
-
-from z3c.relationfield.interfaces import (IHasRelations,
- IRelation,
- IRelationValue,
- ITemporaryRelationValue)
-
- at grok.subscribe(IHasRelations, IObjectAddedEvent)
-def addRelations(obj, event):
- """Register relations.
-
- Any relation object on the object will be added.
- """
- for name, relation in _relations(obj):
- _setRelation(obj, name, relation)
-
- at grok.subscribe(IHasRelations, IObjectRemovedEvent)
-def removeRelations(obj, event):
- """Remove relations.
-
- Any relation object on the object will be removed from the catalog.
- """
- catalog = component.getUtility(ICatalog)
-
- for name, relation in _relations(obj):
- if relation is not None:
- catalog.unindex(relation)
-
- at grok.subscribe(IHasRelations, IObjectModifiedEvent)
-def updateRelations(obj, event):
- """Re-register relations, after they have been changed.
- """
- catalog = component.getUtility(ICatalog)
- intids = component.getUtility(IIntIds)
-
- # remove previous relations coming from id (now have been overwritten)
- for relation in catalog.findRelations({'from_id': intids.getId(obj)}):
- catalog.unindex(relation)
-
- # add new relations
- addRelations(obj, event)
-
-def realize_relations(obj):
- """Given an object, convert any temporary relatiosn on it to real ones.
- """
- for name, relation in _potential_relations(obj):
- if ITemporaryRelationValue.providedBy(relation):
- setattr(obj, name, relation.convert())
-
-def _setRelation(obj, name, value):
- """Set a relation on an object.
-
- Sets up various essential attributes on the relation.
- """
- # if the Relation is None, we're done
- if value is None:
- return
- # make sure relation has a __parent__ so we can make an intid for it
- value.__parent__ = obj
- # also set from_object to parent object
- value.from_object = obj
- # and the attribute to the attribute name
- value.from_attribute = name
- # now we can create an intid for the relation
- intids = component.getUtility(IIntIds)
- id = intids.register(value)
- # and index the relation with the catalog
- catalog = component.getUtility(ICatalog)
- catalog.index_doc(id, value)
-
-def _relations(obj):
- """Given an object, return tuples of name, relation value.
-
- Only real relations are returned, not temporary relations.
- """
- for name, relation in _potential_relations(obj):
- if IRelationValue.providedBy(relation):
- yield name, relation
-
-def _potential_relations(obj):
- """Given an object return tuples of name, relation value.
-
- Returns both IRelationValue attributes as well as ITemporaryRelationValue
- attributes.
- """
- for iface in providedBy(obj).flattened():
- for name, field in getFields(iface).items():
- if IRelation.providedBy(field):
- relation = getattr(obj, name)
- yield name, relation
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftesting.zcml
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftesting.zcml 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/ftesting.zcml 2008-10-17 15:58:34 UTC (rev 92315)
@@ -6,7 +6,7 @@
>
<include package="grok" />
- <include package="z3c.relationfield" />
+ <include package="z3c.relationfieldui" />
<!-- Typical functional testing security setup -->
<securityPolicy
Deleted: z3c.relationfieldui/trunk/src/z3c/relationfieldui/index.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/index.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/index.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,37 +0,0 @@
-import BTrees
-
-from zope import component
-from zope.app.intid.interfaces import IIntIds
-
-from zc.relation.catalog import Catalog
-from zc.relation.interfaces import ICatalog
-
-from z3c.relationfield.interfaces import IRelationValue
-
-def dump(obj, catalog, cache):
- intids = cache.get('intids')
- if intids is None:
- intids = cache['intids'] = component.getUtility(IIntIds)
- return intids.getId(obj)
-
-def load(token, catalog, cache):
- intids = cache.get('intids')
- if intids is None:
- intids = cache['intids'] = component.getUtility(IIntIds)
- return intids.getObject(token)
-
-class RelationCatalog(Catalog):
-
- def __init__(self):
- Catalog.__init__(self, dump, load)
- self.addValueIndex(IRelationValue['from_id'])
- self.addValueIndex(IRelationValue['to_id'])
- self.addValueIndex(IRelationValue['from_attribute'],
- btree=BTrees.family32.OI)
- self.addValueIndex(IRelationValue['from_interfaces_flattened'],
- multiple=True,
- btree=BTrees.family32.OI)
- self.addValueIndex(IRelationValue['to_interfaces_flattened'],
- multiple=True,
- btree=BTrees.family32.OI)
-
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/interfaces.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/interfaces.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/interfaces.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,70 +1,2 @@
-from zope.interface import Interface, Attribute
-from zope.schema.interfaces import IField
+#
-class IHasRelations(Interface):
- """Marker interface indicating that the object has relations.
-
- Use this interface to make sure that the relations get added and
- removed from the catalog when appropriate.
- """
-
-class IRelation(IField):
- pass
-
-class IRelationValue(Interface):
- """A relation between the parent object and another one.
-
- This should be stored as the value in the object when the schema uses the
- Relation field.
- """
- from_object = Attribute("The object this relation is pointing from.")
-
- from_id = Attribute("Id of the object this relation is pointing from.")
-
- from_path = Attribute("The path of the from object.")
-
- from_interfaces = Attribute("The interfaces of the from object.")
-
- from_interfaces_flattened = Attribute(
- "Interfaces of the from object, flattened. "
- "This includes all base interfaces.")
-
- from_attribute = Attribute("The name of the attribute of the from object.")
-
- to_object = Attribute("The object this relation is pointing to.")
-
- to_id = Attribute("Id of the object this relation is pointing to.")
-
- to_path = Attribute("The path of the object this relation is pointing to.")
-
- to_interfaces = Attribute("The interfaces of the to-object.")
-
- to_interfaces_flattened = Attribute(
- "The interfaces of the to object, flattened. "
- "This includes all base interfaces.")
-
-class ITemporaryRelationValue(Interface):
- """A temporary relation.
-
- When importing relations from XML, we cannot resolve them into
- true RelationValue objects yet, as it may be that the object that is
- being related to has not yet been loaded. Instead we create
- a TemporaryRelationValue object that can be converted into a real one
- after the import has been concluded.
- """
- def convert():
- """Convert temporary relation into a real one.
-
- Returns real relation object
- """
-
-
-class IRelationInfo(Interface):
- """Relationship information for an object.
- """
-
- def createRelation():
- """Create a relation object pointing to this object.
-
- Returns an object that provides IRelation.
- """
Deleted: z3c.relationfieldui/trunk/src/z3c/relationfieldui/relation.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/relation.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/relation.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,106 +0,0 @@
-import grokcore.component as grok
-
-from persistent import Persistent
-from zope.interface import implements, providedBy, Declaration
-from zope import component
-from zope.app.intid.interfaces import IIntIds
-
-from z3c.objpath.interfaces import IObjectPath
-
-from z3c.relationfield.interfaces import (IRelationValue,
- ITemporaryRelationValue,
- IRelationInfo)
-
-class RelationValue(Persistent):
- implements(IRelationValue)
-
- def __init__(self, to_id):
- self.to_id = to_id
- # these will be set automatically by RelationProperty
- self.from_object = None
- self.__parent__ = None
- self.from_attribute = None
-
- @property
- def from_id(self):
- intids = component.getUtility(IIntIds)
- return intids.getId(self.from_object)
-
- @property
- def from_path(self):
- return _path(self.from_object)
-
- @property
- def from_interfaces(self):
- return providedBy(self.from_object)
-
- @property
- def from_interfaces_flattened(self):
- return _interfaces_flattened(self.from_interfaces)
-
- @property
- def to_object(self):
- return _object(self.to_id)
-
- @property
- def to_path(self):
- return _path(self.to_object)
-
- @property
- def to_interfaces(self):
- return providedBy(self.to_object)
-
- @property
- def to_interfaces_flattened(self):
- return _interfaces_flattened(self.to_interfaces)
-
- def __cmp__(self, other):
- if other is None:
- return cmp(self.to_id, None)
- return cmp(self.to_id, other.to_id)
-
-class TemporaryRelationValue(Persistent):
- """A relation that isn't fully formed yet.
-
- It needs to be finalized afterwards, when we are sure all potential
- target objects exist.
- """
- grok.implements(ITemporaryRelationValue)
-
- def __init__(self, to_path):
- self.to_path = to_path
-
- def convert(self):
- object_path = component.getUtility(IObjectPath)
- # XXX what if we have a broken relation?
- to_object = object_path.resolve(self.to_path)
- intids = component.getUtility(IIntIds)
- to_id = intids.getId(to_object)
- return RelationValue(to_id)
-
-def _object(id):
- intids = component.getUtility(IIntIds)
- try:
- return intids.getObject(id)
- except KeyError:
- # XXX catching this error is not the right thing to do.
- # instead, breaking a relation by removing an object should
- # be caught and the relation should be adjusted that way.
- return None
-
-def _path(obj):
- if obj is None:
- return ''
- object_path = component.getUtility(IObjectPath)
- return object_path.path(obj)
-
-def _interfaces_flattened(interfaces):
- return Declaration(*interfaces).flattened()
-
-class RelationInfoBase(grok.Adapter):
- grok.baseclass()
- grok.provides(IRelationInfo)
-
- def createRelation(self):
- intids = component.getUtility(IIntIds)
- return Relation(intids.getId(self.context))
Deleted: z3c.relationfieldui/trunk/src/z3c/relationfieldui/schema.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/schema.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/schema.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,31 +0,0 @@
-import grokcore.component as grok
-
-from lxml import etree
-
-from zope.interface import implements
-from zope.schema import Field
-
-import z3c.schema2xml
-
-from z3c.relationfield.interfaces import IRelation
-from z3c.relationfield.relation import TemporaryRelationValue
-
-class Relation(Field):
- implements(IRelation)
-
-class RelationGenerator(grok.Adapter):
- """Eport a relation to XML.
- """
- grok.context(IRelation)
- grok.implements(z3c.schema2xml.IXMLGenerator)
-
- def output(self, container, value):
- element = etree.SubElement(container, self.context.__name__)
- if value is not None:
- element.text = value.to_path
-
- def input(self, element):
- if element.text is None:
- return None
- path = element.text
- return TemporaryRelationValue(path)
Modified: z3c.relationfieldui/trunk/src/z3c/relationfieldui/testing.py
===================================================================
--- z3c.relationfieldui/trunk/src/z3c/relationfieldui/testing.py 2008-10-17 15:43:42 UTC (rev 92314)
+++ z3c.relationfieldui/trunk/src/z3c/relationfieldui/testing.py 2008-10-17 15:58:34 UTC (rev 92315)
@@ -1,7 +1,7 @@
import os
-import z3c.relationfield
+import z3c.relationfieldui
from zope.app.testing.functional import ZCMLLayer
ftesting_zcml = os.path.join(
- os.path.dirname(z3c.relationfield.__file__), 'ftesting.zcml')
+ os.path.dirname(z3c.relationfieldui.__file__), 'ftesting.zcml')
FunctionalLayer = ZCMLLayer(ftesting_zcml, __name__, 'FunctionalLayer')
More information about the Checkins
mailing list