equal
deleted
inserted
replaced
21 |
21 |
22 |
22 |
23 import logging |
23 import logging |
24 from warnings import warn |
24 from warnings import warn |
25 from operator import eq |
25 from operator import eq |
26 |
|
27 from six import string_types, integer_types |
|
28 from six.moves import range |
|
29 |
26 |
30 from logilab.common.registry import Predicate, objectify_predicate |
27 from logilab.common.registry import Predicate, objectify_predicate |
31 |
28 |
32 from yams.schema import BASE_TYPES, role_name |
29 from yams.schema import BASE_TYPES, role_name |
33 from rql.nodes import Function |
30 from rql.nodes import Function |
608 |
605 |
609 def __init__(self, *expected_etypes, **kwargs): |
606 def __init__(self, *expected_etypes, **kwargs): |
610 super(is_instance, self).__init__(**kwargs) |
607 super(is_instance, self).__init__(**kwargs) |
611 self.expected_etypes = expected_etypes |
608 self.expected_etypes = expected_etypes |
612 for etype in self.expected_etypes: |
609 for etype in self.expected_etypes: |
613 assert isinstance(etype, string_types), etype |
610 assert isinstance(etype, str), etype |
614 |
611 |
615 def __str__(self): |
612 def __str__(self): |
616 return '%s(%s)' % (self.__class__.__name__, |
613 return '%s(%s)' % (self.__class__.__name__, |
617 ','.join(str(s) for s in self.expected_etypes)) |
614 ','.join(str(s) for s in self.expected_etypes)) |
618 |
615 |
668 super(score_entity, self).__init__(mode=mode) |
665 super(score_entity, self).__init__(mode=mode) |
669 def intscore(*args, **kwargs): |
666 def intscore(*args, **kwargs): |
670 score = scorefunc(*args, **kwargs) |
667 score = scorefunc(*args, **kwargs) |
671 if not score: |
668 if not score: |
672 return 0 |
669 return 0 |
673 if isinstance(score, integer_types): |
670 if isinstance(score, int): |
674 return score |
671 return score |
675 return 1 |
672 return 1 |
676 self.score_entity = intscore |
673 self.score_entity = intscore |
677 |
674 |
678 |
675 |
1086 transition details (including the entity to which is applied the transition |
1083 transition details (including the entity to which is applied the transition |
1087 but also its original state, transition, destination state, user...). |
1084 but also its original state, transition, destination state, user...). |
1088 |
1085 |
1089 See :class:`cubicweb.entities.wfobjs.TrInfo` for more information. |
1086 See :class:`cubicweb.entities.wfobjs.TrInfo` for more information. |
1090 """ |
1087 """ |
1091 if isinstance(tr_names, string_types): |
1088 if isinstance(tr_names, str): |
1092 tr_names = set((tr_names,)) |
1089 tr_names = set((tr_names,)) |
1093 def match_etype_and_transition(trinfo): |
1090 def match_etype_and_transition(trinfo): |
1094 # take care trinfo.transition is None when calling change_state |
1091 # take care trinfo.transition is None when calling change_state |
1095 return (trinfo.transition and trinfo.transition.name in tr_names |
1092 return (trinfo.transition and trinfo.transition.name in tr_names |
1096 # is_instance() first two arguments are 'cls' (unused, so giving |
1093 # is_instance() first two arguments are 'cls' (unused, so giving |
1286 """ |
1283 """ |
1287 if kwargs and expected: |
1284 if kwargs and expected: |
1288 raise ValueError("match_form_params() can't be called with both " |
1285 raise ValueError("match_form_params() can't be called with both " |
1289 "positional and named arguments") |
1286 "positional and named arguments") |
1290 if expected: |
1287 if expected: |
1291 if len(expected) == 1 and not isinstance(expected[0], string_types): |
1288 if len(expected) == 1 and not isinstance(expected[0], str): |
1292 raise ValueError("match_form_params() positional arguments " |
1289 raise ValueError("match_form_params() positional arguments " |
1293 "must be strings") |
1290 "must be strings") |
1294 super(match_form_params, self).__init__(*expected) |
1291 super(match_form_params, self).__init__(*expected) |
1295 else: |
1292 else: |
1296 super(match_form_params, self).__init__(kwargs) |
1293 super(match_form_params, self).__init__(kwargs) |