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
32
concept.py
32
concept.py
|
@ -63,6 +63,8 @@ from loops.view import TargetRelation
|
|||
|
||||
class BaseRelation(DyadicRelation):
|
||||
|
||||
fallback = '*'
|
||||
|
||||
def __init__(self, first, second, predicate=None):
|
||||
super(BaseRelation, self).__init__(first, second)
|
||||
if predicate is None:
|
||||
|
@ -72,10 +74,16 @@ class BaseRelation(DyadicRelation):
|
|||
self.predicate = predicate
|
||||
|
||||
def getPredicateName(self):
|
||||
if self.predicate is None:
|
||||
return None
|
||||
baseName = super(BaseRelation, self).getPredicateName()
|
||||
id = util.getUidForObject(self.predicate)
|
||||
return '.'.join((baseName, id))
|
||||
|
||||
@property
|
||||
def ident(self):
|
||||
return self.predicate
|
||||
|
||||
# Problem with reindex catalog, needs __parent__ - but this does not help:
|
||||
#__parent__ = None
|
||||
#@property
|
||||
|
@ -89,12 +97,16 @@ class ConceptRelation(BaseRelation):
|
|||
"""
|
||||
implements(IConceptRelation)
|
||||
|
||||
fallback = 'c*'
|
||||
|
||||
|
||||
class ResourceRelation(BaseRelation):
|
||||
""" A relation between a concept and a resource object.
|
||||
"""
|
||||
implements(IConceptRelation)
|
||||
|
||||
fallback = 'r*'
|
||||
|
||||
|
||||
# concept
|
||||
|
||||
|
@ -182,10 +194,10 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def getChildRelations(self, predicates=None, child=None, sort='default',
|
||||
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]
|
||||
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)
|
||||
if canListObject(r.second, noSecurityCheck))
|
||||
return sorted(rels, key=sort)
|
||||
|
@ -196,11 +208,10 @@ class Concept(Contained, Persistent):
|
|||
|
||||
def getParentRelations (self, predicates=None, parent=None, sort='default',
|
||||
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]
|
||||
if sort == 'default':
|
||||
#sort = lambda x: (x.order, x.first.title.lower())
|
||||
sort = lambda x: (x.first.title.lower())
|
||||
sort = lambda x: (x.first.title and x.first.title.lower())
|
||||
rels = (r for r in getRelations(parent, self, relationships=relationships)
|
||||
if canListObject(r.first, noSecurityCheck))
|
||||
return sorted(rels, key=sort)
|
||||
|
@ -278,7 +289,7 @@ class Concept(Contained, Persistent):
|
|||
noSecurityCheck=False):
|
||||
if resource is not None:
|
||||
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]
|
||||
if sort == 'default':
|
||||
sort = lambda x: (x.order, x.second.title.lower())
|
||||
|
@ -447,6 +458,8 @@ class IndexAttributes(object):
|
|||
if self.adaptedIndexAttributes is not None:
|
||||
return self.adaptedIndexAttributes.text()
|
||||
description = self.context.description
|
||||
if description is None:
|
||||
description = u''
|
||||
if isinstance(description, I18NValue):
|
||||
description = ' '.join(description.values())
|
||||
actx = self.adapted
|
||||
|
@ -459,6 +472,8 @@ class IndexAttributes(object):
|
|||
def title(self):
|
||||
context = self.context
|
||||
title = context.title
|
||||
if title is None:
|
||||
title = u''
|
||||
if isinstance(title, I18NValue):
|
||||
title = ' '.join(title.values())
|
||||
return ' '.join((getName(context), title)).strip()
|
||||
|
@ -474,7 +489,10 @@ class IndexAttributes(object):
|
|||
for c in cr:
|
||||
try:
|
||||
principal = pau.getPrincipal(c)
|
||||
creators.append(principal.title)
|
||||
if principal is None:
|
||||
creators.append(c)
|
||||
else:
|
||||
creators.append(principal.title)
|
||||
except PrincipalLookupError:
|
||||
creators.append(c)
|
||||
return creators
|
||||
|
|
|
@ -47,7 +47,7 @@ Type- and text-based queries
|
|||
>>> from loops.expert import query
|
||||
>>> qu = query.Title('ty*')
|
||||
>>> list(qu.apply())
|
||||
[0, 1, 68]
|
||||
[0, 2, 68]
|
||||
|
||||
>>> qu = query.Type('loops:*')
|
||||
>>> len(list(qu.apply()))
|
||||
|
@ -59,7 +59,7 @@ Type- and text-based queries
|
|||
|
||||
>>> qu = query.Type('loops:concept:predicate') & query.Title('t*')
|
||||
>>> list(qu.apply())
|
||||
[1, 29]
|
||||
[2, 29]
|
||||
|
||||
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
|
||||
# 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',
|
||||
noSecurityCheck=False):
|
||||
predicates = predicates is None and ['*'] or predicates
|
||||
predicates = predicates is None and ['r*'] or predicates
|
||||
obj = getMaster(self)
|
||||
relationships = [ResourceRelation(None, obj, p) for p in predicates]
|
||||
if sort == 'default':
|
||||
|
|
|
@ -53,16 +53,16 @@ domain concept (if present, otherwise the top-level type concept):
|
|||
['children', 'description', 'id', 'name', 'parents', 'resources',
|
||||
'title', 'type', 'viewName']
|
||||
>>> 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:
|
||||
|
||||
>>> defaultPred = xrf.getDefaultPredicate()
|
||||
>>> defaultPred['id'], defaultPred['name']
|
||||
('3', u'standard')
|
||||
('14', u'standard')
|
||||
>>> typePred = xrf.getTypePredicate()
|
||||
>>> typePred['id'], typePred['name']
|
||||
('1', u'hasType')
|
||||
('2', u'hasType')
|
||||
>>> typeConcept = xrf.getTypeConcept()
|
||||
>>> typeConcept['id'], typeConcept['name']
|
||||
('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:
|
||||
|
||||
>>> obj2 = xrf.getObjectById('4')
|
||||
>>> obj2 = xrf.getObjectById('3')
|
||||
>>> obj2['id'], obj2['name']
|
||||
('4', u'domain')
|
||||
('3', u'domain')
|
||||
>>> textdoc = xrf.getObjectByName(u'textdocument')
|
||||
>>> textdoc['id'], textdoc['name']
|
||||
('10', u'textdocument')
|
||||
('9', u'textdocument')
|
||||
|
||||
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'predicate', u'task', u'textdocument', u'topic', u'training', u'type']
|
||||
|
||||
>>> pa = xrf.getParents('6')
|
||||
>>> pa = xrf.getParents('5')
|
||||
>>> len(pa)
|
||||
1
|
||||
>>> pa[0]['name']
|
||||
|
|
Loading…
Add table
Reference in a new issue