new has_related_entities selector
authorSylvain Thenault <sylvain.thenault@logilab.fr>
Fri, 19 Dec 2008 14:52:42 +0100
changeset 230 6e71adc5ccdd
parent 229 767ff7f5d5a7
child 231 d740f5f55d30
new has_related_entities selector
common/selectors.py
--- a/common/selectors.py	Thu Dec 18 10:27:57 2008 -0800
+++ b/common/selectors.py	Fri Dec 19 14:52:42 2008 +0100
@@ -12,7 +12,7 @@
 
 from logilab.common.compat import all
 
-from cubicweb import Unauthorized, NoSelectableObject
+from cubicweb import Unauthorized, NoSelectableObject, role
 from cubicweb.cwvreg import DummyCursorError
 from cubicweb.vregistry import chainall, chainfirst, NoSelectableObject
 from cubicweb.cwconfig import CubicWebConfiguration
@@ -337,6 +337,10 @@
             return 0
     return 1
 
+def has_related_entities(cls, req, rset, row=None, col=None, **kwargs):
+    assert row is not None
+    return bool(rset.get_entity(row, col).related(cls.rtype, role(cls)))
+    
 @lltrace
 def one_has_relation_selector(cls, req, rset, row=None, col=None, **kwargs):
     """check if the user has read access on the relations's type refered by the