From 963a167f12b83e4e702506d238bf5f3cb2baada8 Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 9 Nov 2005 11:21:56 +0000 Subject: [PATCH] relation: some minor changes; + __parent__ assignment for relation when registering it git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@668 fd906abe-77d9-0310-91a1-e0d9ade77398 --- relation/README.txt | 22 ++++++++++++++++++---- relation/__init__.py | 15 ++++++++++++--- relation/configure.zcml | 2 +- relation/ftests.py | 2 +- relation/interfaces.py | 16 ++++++++++++++++ relation/registry.py | 28 +++++++++------------------- relation/tests.py | 8 +++++++- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/relation/README.txt b/relation/README.txt index 0a9d48f..be4ad49 100644 --- a/relation/README.txt +++ b/relation/README.txt @@ -1,6 +1,8 @@ Yet Another Relations (Reference) Engine... =========================================== + ($Id$) + >>> from zope.app.testing.placelesssetup import setUp >>> setUp() @@ -122,19 +124,31 @@ working with events). >>> from zope.app import zapi >>> relations = zapi.getUtility(IRelationsRegistry) -In real life the indexes needed will be set up manually after object creation -or via subscription to IObjectCreatedEvent - here we have to do this -explicitly: +In real life the indexes needed will be set up via subscription to +IObjectCreatedEvent - here we have to do this explicitly: >>> relations.setupIndexes() In order to register relations the objects that are referenced have to be registered with an IntIds (unique ids) utility, so we have to set up such -an utility (using a stub/dummy implementation for testing purposes): +an utility (using a stub/dummy implementation for testing purposes) and +register the objects with it (in real life this is done automatically +when we add an object to a container): >>> from cybertools.relation.tests import IntIdsStub >>> from zope.app.intid.interfaces import IIntIds >>> ztapi.provideUtility(IIntIds, IntIdsStub()) + >>> intids = zapi.getUtility(IIntIds) + >>> intids.register(clark) + 0 + >>> intids.register(kirk) + 1 + >>> intids.register(audrey) + 2 + >>> intids.register(washington) + 3 + >>> intids.register(newyork) + 4 We also have to provide an adapter for the Relation objects that provides the attributes needed for indexing: diff --git a/relation/__init__.py b/relation/__init__.py index 73fc03d..5ac8c4b 100644 --- a/relation/__init__.py +++ b/relation/__init__.py @@ -27,10 +27,19 @@ $Id$ from persistent import Persistent from zope.interface import implements -from interfaces import IDyadicRelation, ITriadicRelation +from interfaces import IPredicate +from interfaces import IRelation, IDyadicRelation, ITriadicRelation + +class Relation(Persistent): + + implements(IPredicate, IRelation) + + @classmethod + def getPredicateName(cls): + return '%s.%s' % (cls.__module__, cls.__name__) -class DyadicRelation(Persistent): +class DyadicRelation(Relation): implements(IDyadicRelation) @@ -39,7 +48,7 @@ class DyadicRelation(Persistent): self.second = second -class TriadicRelation(Persistent): +class TriadicRelation(Relation): implements(ITriadicRelation) diff --git a/relation/configure.zcml b/relation/configure.zcml index fb2d37c..5a43d7c 100644 --- a/relation/configure.zcml +++ b/relation/configure.zcml @@ -63,7 +63,7 @@ />