Work in progress: concept relations using predicates...
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1093 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
07b62baa25
commit
09b3bf29e5
3 changed files with 26 additions and 23 deletions
|
@ -88,9 +88,9 @@ class ConceptView(BaseView):
|
|||
predicate = self.loopsRoot.loopsTraverse(relToken)
|
||||
qualifier = self.request.get('qualifier')
|
||||
if qualifier == 'parents':
|
||||
self.context.deassignParents(concept, [predicate])
|
||||
self.context.deassignParent(concept, [predicate])
|
||||
elif qualifier == 'children':
|
||||
self.context.deassignChildren(concept, [predicate])
|
||||
self.context.deassignChild(concept, [predicate])
|
||||
else:
|
||||
raise(BadRequest, 'Illegal qualifier: %s.' % qualifier)
|
||||
else:
|
||||
|
|
24
concept.py
24
concept.py
|
@ -98,7 +98,7 @@ class Concept(Contained, Persistent):
|
|||
if current != concept:
|
||||
typePred = self.getConceptManager().getTypePredicate()
|
||||
if current is not None:
|
||||
self.deassignParents(current, [typePred])
|
||||
self.deassignParent(current, [typePred])
|
||||
self.assignParent(concept, typePred)
|
||||
#cm = self.getLoopsRoot().getConceptManager()
|
||||
#typeRelation = ConceptRelation(removeSecurityProxy(concept), self,
|
||||
|
@ -117,20 +117,20 @@ class Concept(Contained, Persistent):
|
|||
|
||||
# concept relations
|
||||
|
||||
def getChildRelations(self, predicates=None, second=None):
|
||||
def getChildRelations(self, predicates=None, child=None):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
relationships = [ConceptRelation(self, None, p) for p in predicates]
|
||||
# TODO: sort...
|
||||
return getRelations(first=self, second=second, relationships=relationships)
|
||||
return getRelations(first=self, second=child, relationships=relationships)
|
||||
|
||||
def getChildren(self, predicates=None):
|
||||
return [r.second for r in self.getChildRelations(predicates)]
|
||||
|
||||
def getParentRelations (self, predicates=None, first=None):
|
||||
def getParentRelations (self, predicates=None, parent=None):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
relationships = [ConceptRelation(None, self, p) for p in predicates]
|
||||
# TODO: sort...
|
||||
return getRelations(first=first, second=self, relationships=relationships)
|
||||
return getRelations(first=parent, second=self, relationships=relationships)
|
||||
|
||||
def getParents(self, predicates=None):
|
||||
return [r.first for r in self.getParentRelations(predicates)]
|
||||
|
@ -146,25 +146,25 @@ class Concept(Contained, Persistent):
|
|||
def assignParent(self, concept, predicate=None):
|
||||
concept.assignChild(self, predicate)
|
||||
|
||||
def deassignChildren(self, concept, predicates=None):
|
||||
def deassignChild(self, child, predicates=None):
|
||||
registry = zapi.getUtility(IRelationRegistry)
|
||||
#relations = []
|
||||
#for rs in relationships:
|
||||
# relations.extend(registry.query(first=self, second=concept,
|
||||
# relationship=rs))
|
||||
for rel in self.getChildRelations(predicates, concept):
|
||||
for rel in self.getChildRelations(predicates, child):
|
||||
registry.unregister(rel)
|
||||
|
||||
def deassignParents(self, concept, predicates=None):
|
||||
concept.deassignChildren(self, predicates)
|
||||
def deassignParent(self, parent, predicates=None):
|
||||
parent.deassignChild(self, predicates)
|
||||
|
||||
# resource relations
|
||||
|
||||
def getResourceRelations(self, predicates=None):
|
||||
def getResourceRelations(self, predicates=None, resource=None):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
relationships = [ResourceRelation(self, None, p) for p in predicates]
|
||||
# TODO: sort...
|
||||
return getRelations(first=self, relationships=relationships)
|
||||
return getRelations(first=self, second=resource, relationships=relationships)
|
||||
|
||||
def getResources(self, predicates=None):
|
||||
return [r.second for r in self.getResourceRelations(predicates)]
|
||||
|
@ -178,7 +178,7 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def deassignResource(self, resource, predicates=None):
|
||||
registry = zapi.getUtility(IRelationRegistry)
|
||||
for rel in self.getResourceRelations(predicates):
|
||||
for rel in self.getResourceRelations(predicates, resource):
|
||||
registry.unregister(rel)
|
||||
|
||||
|
||||
|
|
|
@ -84,9 +84,10 @@ class IConcept(ILoopsObject, IPotentialTarget):
|
|||
optionally restricted to the predicates given.
|
||||
"""
|
||||
|
||||
def getChildRelations(predicates=None):
|
||||
def getChildRelations(predicates=None, children=None):
|
||||
""" Return a sequence of relations to other concepts assigned to self
|
||||
as child concepts, optionally restricted to the predicates given.
|
||||
as child concepts, optionally restricted to the predicates given
|
||||
or to a certain child concept.
|
||||
"""
|
||||
|
||||
def getParents(predicates=None):
|
||||
|
@ -94,9 +95,10 @@ class IConcept(ILoopsObject, IPotentialTarget):
|
|||
optionally restricted to the predicates given.
|
||||
"""
|
||||
|
||||
def getParentRelations(predicates=None):
|
||||
def getParentRelations(predicates=None, parents=None):
|
||||
""" Return a sequence of relations to other concepts assigned to self
|
||||
as child concepts, optionally restricted to the predicates given.
|
||||
as parent concepts, optionally restricted to the predicates given
|
||||
or to a certain parent concept.
|
||||
"""
|
||||
|
||||
def assignChild(concept, predicate):
|
||||
|
@ -113,13 +115,13 @@ class IConcept(ILoopsObject, IPotentialTarget):
|
|||
The predicate defaults to the concept manager's default predicate.
|
||||
"""
|
||||
|
||||
def deassignChildren(concept, predicates=None):
|
||||
def deassignChild(child, predicates=None):
|
||||
""" Remove the child concept relations to the concept given from self,
|
||||
optionally restricting them to the predicates given.
|
||||
"""
|
||||
|
||||
def deassignParents(concept, predicates=None):
|
||||
""" Remove the child concept relations to the concept given from self,
|
||||
def deassignParent(parent, predicates=None):
|
||||
""" Remove the parent concept relations to the concept given from self,
|
||||
optionally restricting them to the predicates given.
|
||||
"""
|
||||
|
||||
|
@ -128,9 +130,10 @@ class IConcept(ILoopsObject, IPotentialTarget):
|
|||
optionally restricted to the predicates given.
|
||||
"""
|
||||
|
||||
def getResourceRelations(predicates=None):
|
||||
def getResourceRelations(predicates=None, resource=None):
|
||||
""" Return a sequence of relations to resources assigned to self,
|
||||
optionally restricted to the predicates given.
|
||||
optionally restricted to the predicates given or to a certain
|
||||
resource.
|
||||
"""
|
||||
|
||||
def assignResource(resource, predicate):
|
||||
|
|
Loading…
Add table
Reference in a new issue