From 1570c8d680d6b1e571c2ef91b75287be5e4026cd Mon Sep 17 00:00:00 2001 From: helmutm Date: Wed, 5 Oct 2005 18:28:30 +0000 Subject: [PATCH] first steps...; addedd relations package git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@616 fd906abe-77d9-0310-91a1-e0d9ade77398 --- browser/skin/view_macros.pt | 2 +- doc/menu.txt | 25 ++++++++++- menu.py | 8 ++++ relations/__init__.py | 7 ++++ relations/configure.zcml | 21 ++++++++++ relations/interfaces.py | 84 +++++++++++++++++++++++++++++++++++++ relations/utilities.py | 51 ++++++++++++++++++++++ tests/test_cybertools.py | 6 ++- 8 files changed, 199 insertions(+), 5 deletions(-) create mode 100644 relations/__init__.py create mode 100644 relations/configure.zcml create mode 100644 relations/interfaces.py create mode 100644 relations/utilities.py diff --git a/browser/skin/view_macros.pt b/browser/skin/view_macros.pt index 9661305..b0cc3d5 100644 --- a/browser/skin/view_macros.pt +++ b/browser/skin/view_macros.pt @@ -27,8 +27,8 @@
+ + + + + + + + + + + + + + + + diff --git a/relations/interfaces.py b/relations/interfaces.py new file mode 100644 index 0000000..44a2d68 --- /dev/null +++ b/relations/interfaces.py @@ -0,0 +1,84 @@ +# +# Copyright (c) 2005 Helmut Merz helmutm@cy55.de +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +""" +interface definitions for the Relations utility and relation objects. + +$Id$ +""" + +from zope.interface import Interface, Attribute + + +class IRelationsRepository(Interface): + """ Local utility for storing relations. + """ + + def add(relation): + """ Add the relation given and return the id generated for it. + """ + + def remove(relation): + """ Remove the relation given. + """ + + +class IRelationsRegistry(Interface): + """ Local utility for registering (cataloguing) and searching relations. + """ + + def register(relation): + """ Register the relation given with this registry. + """ + + def unregister(relation): + """ Remove the relation given from this registry. + """ + + def query(**kw): + """ Return a list of relations that fulfill the criteria given. + + Example: rr.queryRelations(first=someObject, second=anotherObject, + relationship='a.dotted.name') + """ + + +class IRelation(Interface): + """ Base class for relations. + """ + + relationship = Attribute( + 'A string specific for a kind of relation; e.g. the full module ' + 'path and class name of the class implementing a certain type of relation.') + + +class IDyadicRelation(IRelation): + """ Relation connecting two objects. + """ + + first = Attribute('First object that belongs to the relation.') + second = Attribute('Second object that belongs to the relation.') + + +class ITriadicRelation(IDyadicRelation): + """ Relation connecting three objects. + """ + + third = Attribute('Third object that belongs to the relation.') + + \ No newline at end of file diff --git a/relations/utilities.py b/relations/utilities.py new file mode 100644 index 0000000..a2e2c53 --- /dev/null +++ b/relations/utilities.py @@ -0,0 +1,51 @@ +# +# Copyright (c) 2005 Helmut Merz helmutm@cy55.de +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +""" +Implementation of the utilities needed for the relations package. + +$Id$ +""" + +from zope.interface import implements +from zope.app import zapi + +class RelationsRepository(Persistent, Contained): + """ Local utility for storing relations. + """ + + def add(self, relation): + return 'bla' + + def remove(self, relation): + pass + + +class RelationsRegistry(Persistent, Contained): + """ Local utility for registering (cataloguing) and searching relations. + """ + + def register(self, relation): + pass + + def unregister(relation): + pass + + def query(**kw): + return [] + diff --git a/tests/test_cybertools.py b/tests/test_cybertools.py index e3ef792..bdcfde7 100755 --- a/tests/test_cybertools.py +++ b/tests/test_cybertools.py @@ -13,6 +13,7 @@ from zope.app import zapi from cybertools.menu import Menu from cybertools.interfaces import IMenu + class TestMenu(unittest.TestCase): "Test methods of the Menu class." @@ -21,8 +22,8 @@ class TestMenu(unittest.TestCase): placefulSetUp() self.f1 = Folder() self.f1.__name__ = u'f1' - self.m1 = Menu() - self.f1['m1'] = self.m1 + #self.m1 = Menu() + #self.f1['m1'] = self.m1 def tearDown(self): pass @@ -36,6 +37,7 @@ class TestMenu(unittest.TestCase): 'Interface IContained is not implemented by class Menu.') verifyClass(IMenu, Menu) + def test_suite(): return unittest.TestSuite(( unittest.makeSuite(TestMenu),