diff --git a/relation/__init__.py b/relation/__init__.py index bef1d08..13b445d 100644 --- a/relation/__init__.py +++ b/relation/__init__.py @@ -1,7 +1,7 @@ # -*- coding: UTF-8 -*- # -*- 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 # 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 triadic relations. - -$Id$ """ from persistent import Persistent @@ -37,11 +35,16 @@ class Relation(Persistent): order = 0 relevance = 1.0 + fallback = None @classmethod def getPredicateName(cls): return '%s.%s' % (cls.__module__, cls.__name__) + @property + def ident(self): + return self.getPredicateName() + def validate(self, registry=None): return True diff --git a/relation/registry.py b/relation/registry.py index 001c736..1265b2d 100644 --- a/relation/registry.py +++ b/relation/registry.py @@ -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 # 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. - -$Id$ """ from logging import getLogger @@ -186,7 +184,7 @@ class RelationRegistry(Catalog): if value is not None: criteria[attr] = intids.getId(value) pn = example.getPredicateName() - if pn: + if pn is not None: criteria['relationship'] = pn for k in kw: # overwrite example fields with explicit values @@ -244,10 +242,17 @@ def getRelations(first=None, second=None, third=None, relationships=None): if not relationships: return registry.query(**query) else: - result = set() + predicates = [] for r in relationships: - query['relationship'] = r - result.update(registry.query(**query)) + if hasattr(r, 'predicate'): + 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 def getRelationSingle(obj=None, relationship=None, forSecond=True):