tune relation registry: do not use predicate in catalog query, filter later
This commit is contained in:
parent
0c2bfcc77f
commit
c30b524f07
4 changed files with 36 additions and 18 deletions
30
concept.py
30
concept.py
|
@ -63,6 +63,8 @@ from loops.view import TargetRelation
|
||||||
|
|
||||||
class BaseRelation(DyadicRelation):
|
class BaseRelation(DyadicRelation):
|
||||||
|
|
||||||
|
fallback = '*'
|
||||||
|
|
||||||
def __init__(self, first, second, predicate=None):
|
def __init__(self, first, second, predicate=None):
|
||||||
super(BaseRelation, self).__init__(first, second)
|
super(BaseRelation, self).__init__(first, second)
|
||||||
if predicate is None:
|
if predicate is None:
|
||||||
|
@ -72,10 +74,16 @@ class BaseRelation(DyadicRelation):
|
||||||
self.predicate = predicate
|
self.predicate = predicate
|
||||||
|
|
||||||
def getPredicateName(self):
|
def getPredicateName(self):
|
||||||
|
if self.predicate is None:
|
||||||
|
return None
|
||||||
baseName = super(BaseRelation, self).getPredicateName()
|
baseName = super(BaseRelation, self).getPredicateName()
|
||||||
id = util.getUidForObject(self.predicate)
|
id = util.getUidForObject(self.predicate)
|
||||||
return '.'.join((baseName, id))
|
return '.'.join((baseName, id))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ident(self):
|
||||||
|
return self.predicate
|
||||||
|
|
||||||
# Problem with reindex catalog, needs __parent__ - but this does not help:
|
# Problem with reindex catalog, needs __parent__ - but this does not help:
|
||||||
#__parent__ = None
|
#__parent__ = None
|
||||||
#@property
|
#@property
|
||||||
|
@ -89,12 +97,16 @@ class ConceptRelation(BaseRelation):
|
||||||
"""
|
"""
|
||||||
implements(IConceptRelation)
|
implements(IConceptRelation)
|
||||||
|
|
||||||
|
fallback = 'c*'
|
||||||
|
|
||||||
|
|
||||||
class ResourceRelation(BaseRelation):
|
class ResourceRelation(BaseRelation):
|
||||||
""" A relation between a concept and a resource object.
|
""" A relation between a concept and a resource object.
|
||||||
"""
|
"""
|
||||||
implements(IConceptRelation)
|
implements(IConceptRelation)
|
||||||
|
|
||||||
|
fallback = 'r*'
|
||||||
|
|
||||||
|
|
||||||
# concept
|
# concept
|
||||||
|
|
||||||
|
@ -182,10 +194,10 @@ class Concept(Contained, Persistent):
|
||||||
|
|
||||||
def getChildRelations(self, predicates=None, child=None, sort='default',
|
def getChildRelations(self, predicates=None, child=None, sort='default',
|
||||||
noSecurityCheck=False):
|
noSecurityCheck=False):
|
||||||
predicates = predicates is None and ['*'] or predicates
|
predicates = predicates is None and ['c*'] or predicates
|
||||||
relationships = [ConceptRelation(self, None, p) for p in predicates]
|
relationships = [ConceptRelation(self, None, p) for p in predicates]
|
||||||
if sort == 'default':
|
if sort == 'default':
|
||||||
sort = lambda x: (x.order, x.second.title.lower())
|
sort = lambda x: (x.order, (x.second.title and x.second.title.lower()))
|
||||||
rels = (r for r in getRelations(self, child, relationships=relationships)
|
rels = (r for r in getRelations(self, child, relationships=relationships)
|
||||||
if canListObject(r.second, noSecurityCheck))
|
if canListObject(r.second, noSecurityCheck))
|
||||||
return sorted(rels, key=sort)
|
return sorted(rels, key=sort)
|
||||||
|
@ -196,11 +208,10 @@ class Concept(Contained, Persistent):
|
||||||
|
|
||||||
def getParentRelations (self, predicates=None, parent=None, sort='default',
|
def getParentRelations (self, predicates=None, parent=None, sort='default',
|
||||||
noSecurityCheck=False):
|
noSecurityCheck=False):
|
||||||
predicates = predicates is None and ['*'] or predicates
|
predicates = predicates is None and ['c*'] or predicates
|
||||||
relationships = [ConceptRelation(None, self, p) for p in predicates]
|
relationships = [ConceptRelation(None, self, p) for p in predicates]
|
||||||
if sort == 'default':
|
if sort == 'default':
|
||||||
#sort = lambda x: (x.order, x.first.title.lower())
|
sort = lambda x: (x.first.title and x.first.title.lower())
|
||||||
sort = lambda x: (x.first.title.lower())
|
|
||||||
rels = (r for r in getRelations(parent, self, relationships=relationships)
|
rels = (r for r in getRelations(parent, self, relationships=relationships)
|
||||||
if canListObject(r.first, noSecurityCheck))
|
if canListObject(r.first, noSecurityCheck))
|
||||||
return sorted(rels, key=sort)
|
return sorted(rels, key=sort)
|
||||||
|
@ -278,7 +289,7 @@ class Concept(Contained, Persistent):
|
||||||
noSecurityCheck=False):
|
noSecurityCheck=False):
|
||||||
if resource is not None:
|
if resource is not None:
|
||||||
resource = getMaster(resource)
|
resource = getMaster(resource)
|
||||||
predicates = predicates is None and ['*'] or predicates
|
predicates = predicates is None and ['r*'] or predicates
|
||||||
relationships = [ResourceRelation(self, None, p) for p in predicates]
|
relationships = [ResourceRelation(self, None, p) for p in predicates]
|
||||||
if sort == 'default':
|
if sort == 'default':
|
||||||
sort = lambda x: (x.order, x.second.title.lower())
|
sort = lambda x: (x.order, x.second.title.lower())
|
||||||
|
@ -447,6 +458,8 @@ class IndexAttributes(object):
|
||||||
if self.adaptedIndexAttributes is not None:
|
if self.adaptedIndexAttributes is not None:
|
||||||
return self.adaptedIndexAttributes.text()
|
return self.adaptedIndexAttributes.text()
|
||||||
description = self.context.description
|
description = self.context.description
|
||||||
|
if description is None:
|
||||||
|
description = u''
|
||||||
if isinstance(description, I18NValue):
|
if isinstance(description, I18NValue):
|
||||||
description = ' '.join(description.values())
|
description = ' '.join(description.values())
|
||||||
actx = self.adapted
|
actx = self.adapted
|
||||||
|
@ -459,6 +472,8 @@ class IndexAttributes(object):
|
||||||
def title(self):
|
def title(self):
|
||||||
context = self.context
|
context = self.context
|
||||||
title = context.title
|
title = context.title
|
||||||
|
if title is None:
|
||||||
|
title = u''
|
||||||
if isinstance(title, I18NValue):
|
if isinstance(title, I18NValue):
|
||||||
title = ' '.join(title.values())
|
title = ' '.join(title.values())
|
||||||
return ' '.join((getName(context), title)).strip()
|
return ' '.join((getName(context), title)).strip()
|
||||||
|
@ -474,6 +489,9 @@ class IndexAttributes(object):
|
||||||
for c in cr:
|
for c in cr:
|
||||||
try:
|
try:
|
||||||
principal = pau.getPrincipal(c)
|
principal = pau.getPrincipal(c)
|
||||||
|
if principal is None:
|
||||||
|
creators.append(c)
|
||||||
|
else:
|
||||||
creators.append(principal.title)
|
creators.append(principal.title)
|
||||||
except PrincipalLookupError:
|
except PrincipalLookupError:
|
||||||
creators.append(c)
|
creators.append(c)
|
||||||
|
|
|
@ -47,7 +47,7 @@ Type- and text-based queries
|
||||||
>>> from loops.expert import query
|
>>> from loops.expert import query
|
||||||
>>> qu = query.Title('ty*')
|
>>> qu = query.Title('ty*')
|
||||||
>>> list(qu.apply())
|
>>> list(qu.apply())
|
||||||
[0, 1, 68]
|
[0, 2, 68]
|
||||||
|
|
||||||
>>> qu = query.Type('loops:*')
|
>>> qu = query.Type('loops:*')
|
||||||
>>> len(list(qu.apply()))
|
>>> len(list(qu.apply()))
|
||||||
|
@ -59,7 +59,7 @@ Type- and text-based queries
|
||||||
|
|
||||||
>>> qu = query.Type('loops:concept:predicate') & query.Title('t*')
|
>>> qu = query.Type('loops:concept:predicate') & query.Title('t*')
|
||||||
>>> list(qu.apply())
|
>>> list(qu.apply())
|
||||||
[1, 29]
|
[2, 29]
|
||||||
|
|
||||||
State-based queries
|
State-based queries
|
||||||
-------------------
|
-------------------
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2012 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2013 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
|
||||||
|
@ -199,7 +199,7 @@ class Resource(Image, Contained):
|
||||||
|
|
||||||
def getConceptRelations (self, predicates=None, concept=None, sort='default',
|
def getConceptRelations (self, predicates=None, concept=None, sort='default',
|
||||||
noSecurityCheck=False):
|
noSecurityCheck=False):
|
||||||
predicates = predicates is None and ['*'] or predicates
|
predicates = predicates is None and ['r*'] or predicates
|
||||||
obj = getMaster(self)
|
obj = getMaster(self)
|
||||||
relationships = [ResourceRelation(None, obj, p) for p in predicates]
|
relationships = [ResourceRelation(None, obj, p) for p in predicates]
|
||||||
if sort == 'default':
|
if sort == 'default':
|
||||||
|
|
|
@ -53,16 +53,16 @@ domain concept (if present, otherwise the top-level type concept):
|
||||||
['children', 'description', 'id', 'name', 'parents', 'resources',
|
['children', 'description', 'id', 'name', 'parents', 'resources',
|
||||||
'title', 'type', 'viewName']
|
'title', 'type', 'viewName']
|
||||||
>>> startObj['id'], startObj['name'], startObj['title'], startObj['type']
|
>>> startObj['id'], startObj['name'], startObj['title'], startObj['type']
|
||||||
('4', u'domain', u'Domain', '0')
|
('3', u'domain', u'Domain', '0')
|
||||||
|
|
||||||
There are a few standard objects we can retrieve directly:
|
There are a few standard objects we can retrieve directly:
|
||||||
|
|
||||||
>>> defaultPred = xrf.getDefaultPredicate()
|
>>> defaultPred = xrf.getDefaultPredicate()
|
||||||
>>> defaultPred['id'], defaultPred['name']
|
>>> defaultPred['id'], defaultPred['name']
|
||||||
('3', u'standard')
|
('14', u'standard')
|
||||||
>>> typePred = xrf.getTypePredicate()
|
>>> typePred = xrf.getTypePredicate()
|
||||||
>>> typePred['id'], typePred['name']
|
>>> typePred['id'], typePred['name']
|
||||||
('1', u'hasType')
|
('2', u'hasType')
|
||||||
>>> typeConcept = xrf.getTypeConcept()
|
>>> typeConcept = xrf.getTypeConcept()
|
||||||
>>> typeConcept['id'], typeConcept['name']
|
>>> typeConcept['id'], typeConcept['name']
|
||||||
('0', u'type')
|
('0', u'type')
|
||||||
|
@ -80,12 +80,12 @@ applied in an explicit assignment.
|
||||||
|
|
||||||
We can also retrieve a certain object by its id or its name:
|
We can also retrieve a certain object by its id or its name:
|
||||||
|
|
||||||
>>> obj2 = xrf.getObjectById('4')
|
>>> obj2 = xrf.getObjectById('3')
|
||||||
>>> obj2['id'], obj2['name']
|
>>> obj2['id'], obj2['name']
|
||||||
('4', u'domain')
|
('3', u'domain')
|
||||||
>>> textdoc = xrf.getObjectByName(u'textdocument')
|
>>> textdoc = xrf.getObjectByName(u'textdocument')
|
||||||
>>> textdoc['id'], textdoc['name']
|
>>> textdoc['id'], textdoc['name']
|
||||||
('10', u'textdocument')
|
('9', u'textdocument')
|
||||||
|
|
||||||
All methods that retrieve one object also returns its children and parents:
|
All methods that retrieve one object also returns its children and parents:
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ We can also retrieve children and parents explicitely:
|
||||||
[u'competence', u'customer', u'domain', u'file', u'note', u'person',
|
[u'competence', u'customer', u'domain', u'file', u'note', u'person',
|
||||||
u'predicate', u'task', u'textdocument', u'topic', u'training', u'type']
|
u'predicate', u'task', u'textdocument', u'topic', u'training', u'type']
|
||||||
|
|
||||||
>>> pa = xrf.getParents('6')
|
>>> pa = xrf.getParents('5')
|
||||||
>>> len(pa)
|
>>> len(pa)
|
||||||
1
|
1
|
||||||
>>> pa[0]['name']
|
>>> pa[0]['name']
|
||||||
|
|
Loading…
Add table
Reference in a new issue