equal
deleted
inserted
replaced
51 |
51 |
52 from yams import BASE_TYPES |
52 from yams import BASE_TYPES |
53 |
53 |
54 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity, |
54 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity, |
55 role, typed_eid) |
55 role, typed_eid) |
56 from cubicweb.vregistry import (NoSelectableObject, Selector, |
56 # even if not used, let yes here so it's importable through this module |
57 chainall, objectify_selector) |
57 from cubicweb.appobject import Selector, objectify_selector, yes |
58 from cubicweb.cwconfig import CubicWebConfiguration |
58 from cubicweb.cwconfig import CubicWebConfiguration |
59 from cubicweb.schema import split_expression |
59 from cubicweb.schema import split_expression |
60 |
60 |
61 # helpers for debugging selectors |
61 # helpers for debugging selectors |
62 SELECTOR_LOGGER = logging.getLogger('cubicweb.selectors') |
62 SELECTOR_LOGGER = logging.getLogger('cubicweb.selectors') |
271 def score_entity(self, entity): |
271 def score_entity(self, entity): |
272 raise NotImplementedError() |
272 raise NotImplementedError() |
273 |
273 |
274 |
274 |
275 # very basic selectors ######################################################## |
275 # very basic selectors ######################################################## |
276 |
|
277 class yes(Selector): |
|
278 """return arbitrary score |
|
279 |
|
280 default score of 0.5 so any other selector take precedence |
|
281 """ |
|
282 def __init__(self, score=0.5): |
|
283 self.score = score |
|
284 |
|
285 def __call__(self, *args, **kwargs): |
|
286 return self.score |
|
287 |
276 |
288 @objectify_selector |
277 @objectify_selector |
289 @lltrace |
278 @lltrace |
290 def none_rset(cls, req, rset=None, **kwargs): |
279 def none_rset(cls, req, rset=None, **kwargs): |
291 """accept no result set (e.g. given rset is None)""" |
280 """accept no result set (e.g. given rset is None)""" |
973 super(score_entity, self).__init__(once_is_enough) |
962 super(score_entity, self).__init__(once_is_enough) |
974 self.score_entity = scorefunc |
963 self.score_entity = scorefunc |
975 |
964 |
976 |
965 |
977 # XXX DEPRECATED ############################################################## |
966 # XXX DEPRECATED ############################################################## |
|
967 from cubicweb.vregistry import chainall |
978 |
968 |
979 yes_selector = deprecated()(yes) |
969 yes_selector = deprecated()(yes) |
980 norset_selector = deprecated()(none_rset) |
970 norset_selector = deprecated()(none_rset) |
981 rset_selector = deprecated()(any_rset) |
971 rset_selector = deprecated()(any_rset) |
982 anyrset_selector = deprecated()(nonempty_rset) |
972 anyrset_selector = deprecated()(nonempty_rset) |
1038 accept = chainall(non_final_entity(), accept_rset, name='accept') |
1028 accept = chainall(non_final_entity(), accept_rset, name='accept') |
1039 accept = deprecated('use implements selector')(accept) |
1029 accept = deprecated('use implements selector')(accept) |
1040 accept_selector = deprecated()(accept) |
1030 accept_selector = deprecated()(accept) |
1041 |
1031 |
1042 accept_one = deprecated()(chainall(one_line_rset, accept, |
1032 accept_one = deprecated()(chainall(one_line_rset, accept, |
1043 name='accept_one')) |
1033 name='accept_one')) |
1044 accept_one_selector = deprecated()(accept_one) |
1034 accept_one_selector = deprecated()(accept_one) |
1045 |
1035 |
1046 |
1036 |
1047 def _rql_condition(cls, req, rset=None, row=None, col=0, **kwargs): |
1037 def _rql_condition(cls, req, rset=None, row=None, col=0, **kwargs): |
1048 if cls.condition: |
1038 if cls.condition: |