selectors.py
branchstable
changeset 3315 59220b704562
parent 3276 4480887772a3
child 3293 69c0ba095536
child 3345 10ad3869fc92
equal deleted inserted replaced
3298:caef98aa4a98 3315:59220b704562
   958     :param scorefunc: callable expected to take an entity as argument and to
   958     :param scorefunc: callable expected to take an entity as argument and to
   959                       return a score >= 0
   959                       return a score >= 0
   960     """
   960     """
   961     def __init__(self, scorefunc, once_is_enough=False):
   961     def __init__(self, scorefunc, once_is_enough=False):
   962         super(score_entity, self).__init__(once_is_enough)
   962         super(score_entity, self).__init__(once_is_enough)
   963         self.score_entity = scorefunc
   963         def intscore(*args, **kwargs):
       
   964             score = scorefunc(*args, **kwargs)
       
   965             if not score:
       
   966                 return 0
       
   967             if isinstance(score, (int, long)):
       
   968                 return score
       
   969             return 1
       
   970         self.score_entity = intscore
   964 
   971 
   965 
   972 
   966 # XXX DEPRECATED ##############################################################
   973 # XXX DEPRECATED ##############################################################
   967 from cubicweb.vregistry import chainall
   974 from cubicweb.vregistry import chainall
   968 
   975