tune relation registry: do not use predicate in catalog query, filter later
This commit is contained in:
parent
fae6a82df0
commit
872272adb3
2 changed files with 18 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
# -*- Mode: Python; py-indent-offset: 4 -*-
|
# -*- Mode: Python; py-indent-offset: 4 -*-
|
||||||
#
|
#
|
||||||
# Copyright (c) 2005 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
|
||||||
|
@ -21,8 +21,6 @@
|
||||||
"""
|
"""
|
||||||
The relation package provides all you need for setting up dyadic and
|
The relation package provides all you need for setting up dyadic and
|
||||||
triadic relations.
|
triadic relations.
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from persistent import Persistent
|
from persistent import Persistent
|
||||||
|
@ -37,11 +35,16 @@ class Relation(Persistent):
|
||||||
|
|
||||||
order = 0
|
order = 0
|
||||||
relevance = 1.0
|
relevance = 1.0
|
||||||
|
fallback = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getPredicateName(cls):
|
def getPredicateName(cls):
|
||||||
return '%s.%s' % (cls.__module__, cls.__name__)
|
return '%s.%s' % (cls.__module__, cls.__name__)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ident(self):
|
||||||
|
return self.getPredicateName()
|
||||||
|
|
||||||
def validate(self, registry=None):
|
def validate(self, registry=None):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2009 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
|
||||||
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Implementation of the utilities needed for the relations package.
|
Implementation of the utilities needed for the relations package.
|
||||||
|
|
||||||
$Id$
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from logging import getLogger
|
from logging import getLogger
|
||||||
|
@ -186,7 +184,7 @@ class RelationRegistry(Catalog):
|
||||||
if value is not None:
|
if value is not None:
|
||||||
criteria[attr] = intids.getId(value)
|
criteria[attr] = intids.getId(value)
|
||||||
pn = example.getPredicateName()
|
pn = example.getPredicateName()
|
||||||
if pn:
|
if pn is not None:
|
||||||
criteria['relationship'] = pn
|
criteria['relationship'] = pn
|
||||||
for k in kw:
|
for k in kw:
|
||||||
# overwrite example fields with explicit values
|
# overwrite example fields with explicit values
|
||||||
|
@ -244,10 +242,17 @@ def getRelations(first=None, second=None, third=None, relationships=None):
|
||||||
if not relationships:
|
if not relationships:
|
||||||
return registry.query(**query)
|
return registry.query(**query)
|
||||||
else:
|
else:
|
||||||
result = set()
|
predicates = []
|
||||||
for r in relationships:
|
for r in relationships:
|
||||||
query['relationship'] = r
|
if hasattr(r, 'predicate'):
|
||||||
result.update(registry.query(**query))
|
predicates.append(r.predicate)
|
||||||
|
r.predicate = None
|
||||||
|
else:
|
||||||
|
predicates.append(r.getPredicateName())
|
||||||
|
result = registry.query(**query)
|
||||||
|
if predicates:
|
||||||
|
return [r for r in result
|
||||||
|
if r.ident in predicates or r.fallback in predicates]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
def getRelationSingle(obj=None, relationship=None, forSecond=True):
|
||||||
|
|
Loading…
Add table
Reference in a new issue