work in progress: predicate adapters; import bug fix: import of child relations now OK
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2705 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
580838acb8
commit
878e18d244
8 changed files with 117 additions and 19 deletions
|
@ -213,7 +213,7 @@ class NameChooser(BaseNameChooser):
|
||||||
'\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
|
'\xc4': 'Ae', '\xe4': 'ae', '\xd6': 'Oe', '\xf6': 'oe',
|
||||||
'\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
|
'\xdc': 'Ue', '\xfc': 'ue', '\xdf': 'ss'}
|
||||||
|
|
||||||
# caching
|
# caching (TBD)
|
||||||
|
|
||||||
def cached(obj):
|
def cached(obj):
|
||||||
return obj
|
return obj
|
||||||
|
|
|
@ -250,6 +250,14 @@
|
||||||
set_schema="loops.interfaces.ITypeConcept" />
|
set_schema="loops.interfaces.ITypeConcept" />
|
||||||
</class>
|
</class>
|
||||||
|
|
||||||
|
<adapter factory="loops.predicate.Predicate" trusted="True" />
|
||||||
|
<class class="loops.predicate.Predicate">
|
||||||
|
<require permission="zope.View"
|
||||||
|
interface="loops.interfaces.IPredicate" />
|
||||||
|
<require permission="zope.ManageContent"
|
||||||
|
set_schema="loops.interfaces.IPredicate" />
|
||||||
|
</class>
|
||||||
|
|
||||||
<adapter factory="loops.query.QueryConcept" trusted="True" />
|
<adapter factory="loops.query.QueryConcept" trusted="True" />
|
||||||
<class class="loops.query.QueryConcept">
|
<class class="loops.query.QueryConcept">
|
||||||
<require permission="zope.View"
|
<require permission="zope.View"
|
||||||
|
|
3
external/base.py
vendored
3
external/base.py
vendored
|
@ -25,7 +25,7 @@ $Id$
|
||||||
|
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os, sys
|
||||||
import zdaemon
|
import zdaemon
|
||||||
from zope import component
|
from zope import component
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
@ -77,6 +77,7 @@ class Loader(Base, SetupManager):
|
||||||
def __init__(self, context, resourceDirectory=None):
|
def __init__(self, context, resourceDirectory=None):
|
||||||
super(Loader, self).__init__(context, resourceDirectory)
|
super(Loader, self).__init__(context, resourceDirectory)
|
||||||
self.logger = StringIO()
|
self.logger = StringIO()
|
||||||
|
#self.logger = sys.stdout
|
||||||
|
|
||||||
def load(self, elements):
|
def load(self, elements):
|
||||||
for element in elements:
|
for element in elements:
|
||||||
|
|
15
external/element.py
vendored
15
external/element.py
vendored
|
@ -116,7 +116,7 @@ class ChildElement(Element):
|
||||||
for idx, arg in enumerate(args):
|
for idx, arg in enumerate(args):
|
||||||
self[self.posArgs[idx]] = arg
|
self[self.posArgs[idx]] = arg
|
||||||
|
|
||||||
def __call__(self, loader):
|
def execute(self, loader):
|
||||||
loader.assignChild(self['first'], self['second'], self['predicate'])
|
loader.assignChild(self['first'], self['second'], self['predicate'])
|
||||||
|
|
||||||
|
|
||||||
|
@ -174,14 +174,14 @@ class NodeElement(Element):
|
||||||
def execute(self, loader):
|
def execute(self, loader):
|
||||||
type = self['type']
|
type = self['type']
|
||||||
cont = traverse(loader.views, self['path'])
|
cont = traverse(loader.views, self['path'])
|
||||||
target = self.pop('target', None)
|
#target = self.pop('target', None)
|
||||||
kw = dict((k, v) for k, v in self.items()
|
kw = dict((k, v) for k, v in self.items()
|
||||||
if k not in self.posArgs)
|
if k not in self.posArgs)
|
||||||
node = loader.addNode(self['name'], self['title'], cont, type, **kw)
|
node = loader.addNode(self['name'], self['title'], cont, type, **kw)
|
||||||
if target is not None:
|
#if target is not None:
|
||||||
targetObject = traverse(loader.context, target, None)
|
# targetObject = traverse(loader.context, target, None)
|
||||||
node.target = targetObject
|
# node.target = targetObject
|
||||||
self.object = node
|
#self.object = node
|
||||||
|
|
||||||
|
|
||||||
# element registry
|
# element registry
|
||||||
|
@ -196,4 +196,5 @@ elementTypes = dict(
|
||||||
I18NValue=I18NValue,
|
I18NValue=I18NValue,
|
||||||
)
|
)
|
||||||
|
|
||||||
toplevelElements = ('type', 'concept', 'resource', 'resourceRelation', 'node')
|
toplevelElements = ('type', 'concept', 'resource',
|
||||||
|
'child', 'resourceRelation', 'node')
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2004 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# 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
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -611,7 +611,6 @@ class IIndexAttributes(Interface):
|
||||||
|
|
||||||
# types stuff
|
# types stuff
|
||||||
|
|
||||||
#class ITypeConcept(Interface):
|
|
||||||
class ITypeConcept(IConceptSchema):
|
class ITypeConcept(IConceptSchema):
|
||||||
""" Concepts of type 'type' should be adaptable to this interface.
|
""" Concepts of type 'type' should be adaptable to this interface.
|
||||||
"""
|
"""
|
||||||
|
@ -641,6 +640,21 @@ class ITypeConcept(IConceptSchema):
|
||||||
# storage = schema.Choice()
|
# storage = schema.Choice()
|
||||||
|
|
||||||
|
|
||||||
|
class IPredicate(IConceptSchema):
|
||||||
|
""" Provided by predicates (predicate concepts that specify relation types),
|
||||||
|
i.e. concepts of type 'predicate' should be adaptable to this interface.
|
||||||
|
"""
|
||||||
|
|
||||||
|
typeInterface = schema.TextLine( #schema.Choice
|
||||||
|
title=_(u'Type Interface'),
|
||||||
|
description=_(u'Optional: allows specification of additional '
|
||||||
|
'attributes of relations that are instances of this '
|
||||||
|
'predicate.'),
|
||||||
|
default=u'', #None
|
||||||
|
#source="loops.TypeInterfaceSource",
|
||||||
|
required=False)
|
||||||
|
|
||||||
|
|
||||||
class IResourceAdapter(IBaseResourceSchema):
|
class IResourceAdapter(IBaseResourceSchema):
|
||||||
""" Base interface for adapters for resources. This is the base interface
|
""" Base interface for adapters for resources. This is the base interface
|
||||||
of the interfaces to be used as typeInterface attribute on type concepts
|
of the interfaces to be used as typeInterface attribute on type concepts
|
||||||
|
|
58
predicate.py
Normal file
58
predicate.py
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#
|
||||||
|
# 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
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Predicate management.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
from zope import component, schema
|
||||||
|
from zope.component import adapts
|
||||||
|
from zope.interface import implements
|
||||||
|
from zope.cachedescriptors.property import Lazy
|
||||||
|
from zope.dottedname.resolve import resolve
|
||||||
|
from zope.security.proxy import removeSecurityProxy
|
||||||
|
from zope.traversing.api import getName
|
||||||
|
|
||||||
|
from loops.interfaces import ILoopsObject, IConcept, IResource
|
||||||
|
from loops.interfaces import IPredicate
|
||||||
|
from loops.concept import Concept
|
||||||
|
from loops.common import AdapterBase
|
||||||
|
from loops.type import TypeInterfaceSourceList as BaseTypeInterfaceSourceList
|
||||||
|
|
||||||
|
|
||||||
|
BaseTypeInterfaceSourceList.typeInterfaces += (IPredicate,)
|
||||||
|
|
||||||
|
|
||||||
|
class Predicate(AdapterBase):
|
||||||
|
""" typeInterface adapter for concepts of type 'predicate'.
|
||||||
|
"""
|
||||||
|
|
||||||
|
implements(IPredicate)
|
||||||
|
|
||||||
|
_contextAttributes = list(IPredicate) + list(IConcept)
|
||||||
|
|
||||||
|
|
||||||
|
class TypeInterfaceSourceList(BaseTypeInterfaceSourceList):
|
||||||
|
""" Collects type interfaces for predicates, i.e. interfaces that
|
||||||
|
may be used for specifying additional attributes of relations.
|
||||||
|
"""
|
||||||
|
|
||||||
|
typeInterfaces = ()
|
||||||
|
|
30
setup.py
30
setup.py
|
@ -28,7 +28,7 @@ from zope import component
|
||||||
from zope.cachedescriptors.property import Lazy
|
from zope.cachedescriptors.property import Lazy
|
||||||
from zope.component import adapts
|
from zope.component import adapts
|
||||||
from zope.interface import implements, Interface
|
from zope.interface import implements, Interface
|
||||||
from zope.traversing.api import getName
|
from zope.traversing.api import getName, traverse
|
||||||
|
|
||||||
from cybertools.typology.interfaces import IType
|
from cybertools.typology.interfaces import IType
|
||||||
from loops.common import adapted
|
from loops.common import adapted
|
||||||
|
@ -160,10 +160,12 @@ class SetupManager(object):
|
||||||
concept = self.concepts[conceptName]
|
concept = self.concepts[conceptName]
|
||||||
child = self.concepts[childName]
|
child = self.concepts[childName]
|
||||||
if child in concept.getChildren([predicate]):
|
if child in concept.getChildren([predicate]):
|
||||||
self.log("Concept '%s' is already a child of '%s with predicate '%s'.'" %
|
self.log("Concept '%s' is already a child of '%s' with predicate '%s'.'" %
|
||||||
(childName, conceptName, getName(predicate)))
|
(childName, conceptName, getName(predicate)))
|
||||||
else:
|
else:
|
||||||
concept.assignChild(child, predicate)
|
concept.assignChild(child, predicate)
|
||||||
|
self.log("Concept '%s' assigned to '%s with predicate '%s'.'" %
|
||||||
|
(childName, conceptName, getName(predicate)))
|
||||||
|
|
||||||
def addResource(self, name, title, resourceType, description=u'', **kw):
|
def addResource(self, name, title, resourceType, description=u'', **kw):
|
||||||
if name in self.resources:
|
if name in self.resources:
|
||||||
|
@ -187,13 +189,15 @@ class SetupManager(object):
|
||||||
concept = self.concepts[conceptName]
|
concept = self.concepts[conceptName]
|
||||||
resource = self.resources[resourceName]
|
resource = self.resources[resourceName]
|
||||||
if resource in concept.getResources([predicate]):
|
if resource in concept.getResources([predicate]):
|
||||||
self.log("Concept '%s' is already assigned to '%s with predicate '%s'.'" %
|
self.log("Resource '%s' is already assigned to '%s with predicate '%s'.'" %
|
||||||
(conceptName, resourceName, getName(predicate)))
|
(resourceName, conceptName, getName(predicate)))
|
||||||
else:
|
else:
|
||||||
concept.assignResource(resource, predicate)
|
concept.assignResource(resource, predicate)
|
||||||
|
self.log("Resource '%s' assigned to '%s with predicate '%s'.'" %
|
||||||
|
(resourceName, conceptName, getName(predicate)))
|
||||||
|
|
||||||
def addNode(self, name, title, container=None, nodeType='page',
|
def addNode(self, name, title, container=None, nodeType='page',
|
||||||
description=u'', body=u'', targetName=None, **kw):
|
description=u'', body=u'', target=None, **kw):
|
||||||
if container is None:
|
if container is None:
|
||||||
container = self.views
|
container = self.views
|
||||||
nodeType = 'menu'
|
nodeType = 'menu'
|
||||||
|
@ -209,9 +213,19 @@ class SetupManager(object):
|
||||||
description=description, body=body,
|
description=description, body=body,
|
||||||
nodeType=nodeType, **kw)
|
nodeType=nodeType, **kw)
|
||||||
self.log("Node '%s' ('%s') created." % (name, title))
|
self.log("Node '%s' ('%s') created." % (name, title))
|
||||||
if targetName is not None:
|
if target is not None:
|
||||||
if targetName in self.concepts:
|
targetObject = traverse(self, target, None)
|
||||||
n.target = self.concepts[targetName]
|
if targetObject is not None:
|
||||||
|
if n.target == targetObject:
|
||||||
|
self.log("Target '%s' already assigned to node '%s'." %
|
||||||
|
(target, name))
|
||||||
|
else:
|
||||||
|
n.target = targetObject
|
||||||
|
self.log("Target '%s' assigned to node '%s'." %
|
||||||
|
(target, name))
|
||||||
|
else:
|
||||||
|
self.log("Target '%s' for '%s' does not exist." %
|
||||||
|
(target, name))
|
||||||
return n
|
return n
|
||||||
|
|
||||||
def log(self, message):
|
def log(self, message):
|
||||||
|
|
|
@ -54,6 +54,7 @@ from loops.interfaces import ILoopsObject, IIndexAttributes
|
||||||
from loops.interfaces import IDocument, IFile, ITextDocument
|
from loops.interfaces import IDocument, IFile, ITextDocument
|
||||||
from loops.organize.memberinfo import MemberInfoProvider
|
from loops.organize.memberinfo import MemberInfoProvider
|
||||||
from loops.organize.stateful.base import StatefulResourceIndexInfo, handleTransition
|
from loops.organize.stateful.base import StatefulResourceIndexInfo, handleTransition
|
||||||
|
from loops.predicate import Predicate
|
||||||
from loops.query import QueryConcept
|
from loops.query import QueryConcept
|
||||||
from loops.query import QueryConcept
|
from loops.query import QueryConcept
|
||||||
from loops.resource import Resource, FileAdapter, TextDocumentAdapter
|
from loops.resource import Resource, FileAdapter, TextDocumentAdapter
|
||||||
|
@ -110,6 +111,7 @@ class TestSite(object):
|
||||||
|
|
||||||
component.provideAdapter(LoopsType)
|
component.provideAdapter(LoopsType)
|
||||||
component.provideAdapter(ConceptType)
|
component.provideAdapter(ConceptType)
|
||||||
|
component.provideAdapter(Predicate)
|
||||||
component.provideAdapter(ResourceType, (IDocument,))
|
component.provideAdapter(ResourceType, (IDocument,))
|
||||||
component.provideAdapter(TypeConcept)
|
component.provideAdapter(TypeConcept)
|
||||||
component.provideAdapter(QueryConcept)
|
component.provideAdapter(QueryConcept)
|
||||||
|
|
Loading…
Add table
Reference in a new issue