added compound and constraint packages
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2261 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
8c136ea16b
commit
d40012fb18
10 changed files with 264 additions and 0 deletions
6
compound/README.txt
Normal file
6
compound/README.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
===============================================================
|
||||||
|
loops - Linked Objects for Organization and Processing Services
|
||||||
|
===============================================================
|
||||||
|
|
||||||
|
($Id$)
|
||||||
|
|
4
compound/__init__.py
Normal file
4
compound/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
24
compound/base.py
Normal file
24
compound/base.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2008 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Compound objects like articles, blog posts, storyboard items, ...
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
61
compound/interfaces.py
Normal file
61
compound/interfaces.py
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2008 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Compound objects like articles, blog posts, storyboard items, ...
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.interface import Interface, Attribute
|
||||||
|
from zope import interface, component, schema
|
||||||
|
|
||||||
|
from loops.util import _
|
||||||
|
|
||||||
|
|
||||||
|
class ICompound(Interface):
|
||||||
|
""" A compound is a concept that is built up of other objects, its
|
||||||
|
components.
|
||||||
|
|
||||||
|
These components are typically resources, but may also be other
|
||||||
|
concepts that should provide the ICompound interface as their
|
||||||
|
type interface. The components are assigned in an ordered way
|
||||||
|
so that the components are accessed in a reproducible order.
|
||||||
|
|
||||||
|
The components are bound to the compound via standard resource
|
||||||
|
or concept relations using a special predicate, ``ispartof``.
|
||||||
|
"""
|
||||||
|
|
||||||
|
components = Attribute('Objects (resources or other compounds) that '
|
||||||
|
'this object consists of')
|
||||||
|
|
||||||
|
def add(obj, position=None):
|
||||||
|
""" Add a component to the compound.
|
||||||
|
|
||||||
|
If the ``position`` argument is None, append it to the end
|
||||||
|
of the current list of components, otherwise insert it before
|
||||||
|
the position given. The numbering of the positions is like for
|
||||||
|
Python lists, so 0 means before the first one, -1 before the
|
||||||
|
last one.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def reorder(components):
|
||||||
|
""" Change the order settings of the relations that connect the
|
||||||
|
components given (a sequence) to the compound so that they are
|
||||||
|
ordered according to this sequence.
|
||||||
|
"""
|
24
compound/tests.py
Executable file
24
compound/tests.py
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
import unittest, doctest
|
||||||
|
from zope.testing.doctestunit import DocFileSuite
|
||||||
|
from zope.app.testing import ztapi
|
||||||
|
from zope.interface.verify import verifyClass
|
||||||
|
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
"Basic tests for the loops.compound package."
|
||||||
|
|
||||||
|
def testSomething(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_suite():
|
||||||
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
|
return unittest.TestSuite((
|
||||||
|
unittest.makeSuite(Test),
|
||||||
|
DocFileSuite('README.txt', optionflags=flags),
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(defaultTest='test_suite')
|
6
constraint/README.txt
Normal file
6
constraint/README.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
===============================================================
|
||||||
|
loops - Linked Objects for Organization and Processing Services
|
||||||
|
===============================================================
|
||||||
|
|
||||||
|
($Id$)
|
||||||
|
|
4
constraint/__init__.py
Normal file
4
constraint/__init__.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
"""
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
25
constraint/base.py
Normal file
25
constraint/base.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2008 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Constraint definitions for restricting concepts and predicates available
|
||||||
|
for assignment as children or as concepts to resources.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
86
constraint/interfaces.py
Normal file
86
constraint/interfaces.py
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2007 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Constraint definitions for restricting concepts and predicates available
|
||||||
|
for assignment as children or as concepts to resources.
|
||||||
|
|
||||||
|
Constraints may be used to build up an ontology, in the sense of a
|
||||||
|
ruleset that governs the possible relationships between objects.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope.interface import Interface, Attribute
|
||||||
|
from zope import interface, component, schema
|
||||||
|
|
||||||
|
from loops.util import _
|
||||||
|
|
||||||
|
|
||||||
|
class IConstraint(Interface):
|
||||||
|
""" A constraint is an adapter for concepts and resources and
|
||||||
|
provides information on which relations are allowed for its
|
||||||
|
client object.
|
||||||
|
|
||||||
|
When the client object is a concept the constraint checks
|
||||||
|
for child relations, if it is a resource it checks for concept
|
||||||
|
relations. In order to check for allowed parent relations (on
|
||||||
|
a concept only) you may specify ``relationType=parent``
|
||||||
|
on the method calls.
|
||||||
|
"""
|
||||||
|
|
||||||
|
client = Attribute('Object that will be checked for allowed relations.')
|
||||||
|
|
||||||
|
def isRelationAllowed(concept, predicate, relationType=None):
|
||||||
|
""" Return True if this constraint allows the assignment of a
|
||||||
|
relation to the client object specified by the target concept
|
||||||
|
and the predicate given.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def getAllowedPredicates(relationType=None):
|
||||||
|
""" Return a sequence of concepts of type ``predicate`` that
|
||||||
|
may be used for assigning concepts to the client object.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def getAllowedConcepts(predicate, candidates=None, relationType=None):
|
||||||
|
""" Return an iterable of concepts that - according to this
|
||||||
|
constraint - may be assigned to the client object via the
|
||||||
|
predicate given.
|
||||||
|
|
||||||
|
If given, use candidates as a list of concepts from
|
||||||
|
which to select the allowed targets.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class IStaticConstraint(IConstraint):
|
||||||
|
""" Provides a statically assigned contstraint setting.
|
||||||
|
|
||||||
|
Typically used as a concept adapter for a persistent constraint
|
||||||
|
that allows editing of predicates, target types and cardinality
|
||||||
|
of allowed relationships.
|
||||||
|
"""
|
||||||
|
|
||||||
|
relationType = schema.TextLine()
|
||||||
|
|
||||||
|
predicates = schema.List()
|
||||||
|
|
||||||
|
types = schema.List()
|
||||||
|
|
||||||
|
cardinality = schema.List()
|
||||||
|
|
24
constraint/tests.py
Executable file
24
constraint/tests.py
Executable file
|
@ -0,0 +1,24 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
import unittest, doctest
|
||||||
|
from zope.testing.doctestunit import DocFileSuite
|
||||||
|
from zope.app.testing import ztapi
|
||||||
|
from zope.interface.verify import verifyClass
|
||||||
|
|
||||||
|
|
||||||
|
class Test(unittest.TestCase):
|
||||||
|
"Basic tests for the loops.constraint package."
|
||||||
|
|
||||||
|
def testSomething(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def test_suite():
|
||||||
|
flags = doctest.NORMALIZE_WHITESPACE | doctest.ELLIPSIS
|
||||||
|
return unittest.TestSuite((
|
||||||
|
unittest.makeSuite(Test),
|
||||||
|
DocFileSuite('README.txt', optionflags=flags),
|
||||||
|
))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(defaultTest='test_suite')
|
Loading…
Add table
Reference in a new issue