selectors.py
branchtls-sprint
changeset 764 9de67b681624
parent 759 e044f28372bd
child 766 33ede72b22b8
equal deleted inserted replaced
763:db18ecbed8f6 764:9de67b681624
   768             rql = 'Any X WHERE X eid %%(x)s, %s' % expression
   768             rql = 'Any X WHERE X eid %%(x)s, %s' % expression
   769         self.rql = rql
   769         self.rql = rql
   770         
   770         
   771     def score(self, req, rset, row, col):
   771     def score(self, req, rset, row, col):
   772         try:
   772         try:
   773             return len(req.execute(self.rql, {'x': eid, 'u': req.user.eid}, 'x'))
   773             return len(req.execute(self.rql, {'x': rset[row][col],
       
   774                                               'u': req.user.eid}, 'x'))
   774         except Unauthorized:
   775         except Unauthorized:
   775             return 0
   776             return 0
   776 
   777 
   777         
   778         
   778 class but_etype(EntitySelector):
   779 class but_etype(EntitySelector):
   798     See `EntitySelector` documentation for behaviour when row is not specified.
   799     See `EntitySelector` documentation for behaviour when row is not specified.
   799 
   800 
   800     :param scorefunc: callable expected to take an entity as argument and to
   801     :param scorefunc: callable expected to take an entity as argument and to
   801                       return a score >= 0 
   802                       return a score >= 0 
   802     """
   803     """
   803     def __init__(self, scorefunc):
   804     def __init__(self, scorefunc, once_is_enough=False):
       
   805         super(EntitySelector, self).__init__(once_is_enough)
   804         self.score_entity = scorefunc
   806         self.score_entity = scorefunc
   805 
   807 
   806 
   808 
   807 # XXX DEPRECATED ##############################################################
   809 # XXX DEPRECATED ##############################################################
   808 
   810