common/selectors.py
changeset 230 6e71adc5ccdd
parent 215 dfb4ca3ffe78
child 236 8ab9e72dd8f1
equal deleted inserted replaced
229:767ff7f5d5a7 230:6e71adc5ccdd
    10 
    10 
    11 __docformat__ = "restructuredtext en"
    11 __docformat__ = "restructuredtext en"
    12 
    12 
    13 from logilab.common.compat import all
    13 from logilab.common.compat import all
    14 
    14 
    15 from cubicweb import Unauthorized, NoSelectableObject
    15 from cubicweb import Unauthorized, NoSelectableObject, role
    16 from cubicweb.cwvreg import DummyCursorError
    16 from cubicweb.cwvreg import DummyCursorError
    17 from cubicweb.vregistry import chainall, chainfirst, NoSelectableObject
    17 from cubicweb.vregistry import chainall, chainfirst, NoSelectableObject
    18 from cubicweb.cwconfig import CubicWebConfiguration
    18 from cubicweb.cwconfig import CubicWebConfiguration
    19 from cubicweb.schema import split_expression
    19 from cubicweb.schema import split_expression
    20 
    20 
   335                     return 0
   335                     return 0
   336         elif not cls.relation_possible(rset.description[row][col or 0]):
   336         elif not cls.relation_possible(rset.description[row][col or 0]):
   337             return 0
   337             return 0
   338     return 1
   338     return 1
   339 
   339 
       
   340 def has_related_entities(cls, req, rset, row=None, col=None, **kwargs):
       
   341     assert row is not None
       
   342     return bool(rset.get_entity(row, col).related(cls.rtype, role(cls)))
       
   343     
   340 @lltrace
   344 @lltrace
   341 def one_has_relation_selector(cls, req, rset, row=None, col=None, **kwargs):
   345 def one_has_relation_selector(cls, req, rset, row=None, col=None, **kwargs):
   342     """check if the user has read access on the relations's type refered by the
   346     """check if the user has read access on the relations's type refered by the
   343     .rtype attribute of the class, and if at least one entity type in the
   347     .rtype attribute of the class, and if at least one entity type in the
   344     result set has this relation.
   348     result set has this relation.