285 def __call__(self, *args, **kwargs): |
285 def __call__(self, *args, **kwargs): |
286 return self.score |
286 return self.score |
287 |
287 |
288 @objectify_selector |
288 @objectify_selector |
289 @lltrace |
289 @lltrace |
290 def none_rset(cls, req, rset, *args, **kwargs): |
290 def none_rset(cls, req, rset=None, *args, **kwargs): |
291 """accept no result set (e.g. given rset is None)""" |
291 """accept no result set (e.g. given rset is None)""" |
292 if rset is None: |
292 if rset is None: |
293 return 1 |
293 return 1 |
294 return 0 |
294 return 0 |
295 |
295 |
296 @objectify_selector |
296 @objectify_selector |
297 @lltrace |
297 @lltrace |
298 def any_rset(cls, req, rset, *args, **kwargs): |
298 def any_rset(cls, req, rset=None, *args, **kwargs): |
299 """accept result set, whatever the number of result it contains""" |
299 """accept result set, whatever the number of result it contains""" |
300 if rset is not None: |
300 if rset is not None: |
301 return 1 |
301 return 1 |
302 return 0 |
302 return 0 |
303 |
303 |
304 @objectify_selector |
304 @objectify_selector |
305 @lltrace |
305 @lltrace |
306 def nonempty_rset(cls, req, rset, *args, **kwargs): |
306 def nonempty_rset(cls, req, rset=None, *args, **kwargs): |
307 """accept any non empty result set""" |
307 """accept any non empty result set""" |
308 if rset is not None and rset.rowcount: |
308 if rset is not None and rset.rowcount: |
309 return 1 |
309 return 1 |
310 return 0 |
310 return 0 |
311 |
311 |
312 @objectify_selector |
312 @objectify_selector |
313 @lltrace |
313 @lltrace |
314 def empty_rset(cls, req, rset, *args, **kwargs): |
314 def empty_rset(cls, req, rset=None, *args, **kwargs): |
315 """accept empty result set""" |
315 """accept empty result set""" |
316 if rset is not None and rset.rowcount == 0: |
316 if rset is not None and rset.rowcount == 0: |
317 return 1 |
317 return 1 |
318 return 0 |
318 return 0 |
319 |
319 |
320 @objectify_selector |
320 @objectify_selector |
321 @lltrace |
321 @lltrace |
322 def one_line_rset(cls, req, rset, row=None, *args, **kwargs): |
322 def one_line_rset(cls, req, rset=None, row=None, *args, **kwargs): |
323 """if row is specified, accept result set with a single line of result, |
323 """if row is specified, accept result set with a single line of result, |
324 else accepts anyway |
324 else accepts anyway |
325 """ |
325 """ |
326 if rset is not None and (row is not None or rset.rowcount == 1): |
326 if rset is not None and (row is not None or rset.rowcount == 1): |
327 return 1 |
327 return 1 |
328 return 0 |
328 return 0 |
329 |
329 |
330 @objectify_selector |
330 @objectify_selector |
331 @lltrace |
331 @lltrace |
332 def two_lines_rset(cls, req, rset, *args, **kwargs): |
332 def two_lines_rset(cls, req, rset=None, *args, **kwargs): |
333 """accept result set with *at least* two lines of result""" |
333 """accept result set with *at least* two lines of result""" |
334 if rset is not None and rset.rowcount > 1: |
334 if rset is not None and rset.rowcount > 1: |
335 return 1 |
335 return 1 |
336 return 0 |
336 return 0 |
337 |
337 |
338 @objectify_selector |
338 @objectify_selector |
339 @lltrace |
339 @lltrace |
340 def two_cols_rset(cls, req, rset, *args, **kwargs): |
340 def two_cols_rset(cls, req, rset=None, *args, **kwargs): |
341 """accept result set with at least one line and two columns of result""" |
341 """accept result set with at least one line and two columns of result""" |
342 if rset is not None and rset.rowcount and len(rset.rows[0]) > 1: |
342 if rset is not None and rset.rowcount and len(rset.rows[0]) > 1: |
343 return 1 |
343 return 1 |
344 return 0 |
344 return 0 |
345 |
345 |
346 @objectify_selector |
346 @objectify_selector |
347 @lltrace |
347 @lltrace |
348 def paginated_rset(cls, req, rset, *args, **kwargs): |
348 def paginated_rset(cls, req, rset=None, *args, **kwargs): |
349 """accept result set with more lines than the page size. |
349 """accept result set with more lines than the page size. |
350 |
350 |
351 Page size is searched in (respecting order): |
351 Page size is searched in (respecting order): |
352 * a page_size argument |
352 * a page_size argument |
353 * a page_size form parameters |
353 * a page_size form parameters |
418 def anonymous_user(): |
418 def anonymous_user(): |
419 return ~ authenticated_user() |
419 return ~ authenticated_user() |
420 |
420 |
421 @objectify_selector |
421 @objectify_selector |
422 @lltrace |
422 @lltrace |
423 def primary_view(cls, req, rset, row=None, col=0, view=None, **kwargs): |
423 def primary_view(cls, req, rset=None, row=None, col=0, view=None, **kwargs): |
424 """accept if view given as named argument is a primary view, or if no view |
424 """accept if view given as named argument is a primary view, or if no view |
425 is given |
425 is given |
426 """ |
426 """ |
427 if view is not None and not view.is_primary(): |
427 if view is not None and not view.is_primary(): |
428 return 0 |
428 return 0 |
429 return 1 |
429 return 1 |
430 |
430 |
431 @objectify_selector |
431 @objectify_selector |
432 @lltrace |
432 @lltrace |
433 def match_context_prop(cls, req, rset, row=None, col=0, context=None, |
433 def match_context_prop(cls, req, rset=None, row=None, col=0, context=None, |
434 **kwargs): |
434 **kwargs): |
435 """accept if: |
435 """accept if: |
436 * no context given |
436 * no context given |
437 * context (`basestring`) is matching the context property value for the |
437 * context (`basestring`) is matching the context property value for the |
438 given cls |
438 given cls |
983 anonymous_selector = deprecated_function(anonymous_user) |
983 anonymous_selector = deprecated_function(anonymous_user) |
984 not_anonymous_selector = deprecated_function(authenticated_user) |
984 not_anonymous_selector = deprecated_function(authenticated_user) |
985 primaryview_selector = deprecated_function(primary_view) |
985 primaryview_selector = deprecated_function(primary_view) |
986 contextprop_selector = deprecated_function(match_context_prop) |
986 contextprop_selector = deprecated_function(match_context_prop) |
987 |
987 |
988 def nfentity_selector(cls, req, rset, row=None, col=0, **kwargs): |
988 def nfentity_selector(cls, req, rset=None, row=None, col=0, **kwargs): |
989 return non_final_entity()(cls, req, rset, row, col) |
989 return non_final_entity()(cls, req, rset, row, col) |
990 nfentity_selector = deprecated_function(nfentity_selector) |
990 nfentity_selector = deprecated_function(nfentity_selector) |
991 |
991 |
992 def implement_interface(cls, req, rset, row=None, col=0, **kwargs): |
992 def implement_interface(cls, req, rset=None, row=None, col=0, **kwargs): |
993 return implements(*cls.accepts_interfaces)(cls, req, rset, row, col) |
993 return implements(*cls.accepts_interfaces)(cls, req, rset, row, col) |
994 _interface_selector = deprecated_function(implement_interface) |
994 _interface_selector = deprecated_function(implement_interface) |
995 interface_selector = deprecated_function(implement_interface) |
995 interface_selector = deprecated_function(implement_interface) |
996 implement_interface = deprecated_function(implement_interface, 'use implements') |
996 implement_interface = deprecated_function(implement_interface, 'use implements') |
997 |
997 |
999 """check etype presence in request form *and* accepts conformance""" |
999 """check etype presence in request form *and* accepts conformance""" |
1000 return specified_etype_implements(*cls.accepts)(cls, req, *args) |
1000 return specified_etype_implements(*cls.accepts)(cls, req, *args) |
1001 etype_form_selector = deprecated_function(accept_etype) |
1001 etype_form_selector = deprecated_function(accept_etype) |
1002 accept_etype = deprecated_function(accept_etype, 'use specified_etype_implements') |
1002 accept_etype = deprecated_function(accept_etype, 'use specified_etype_implements') |
1003 |
1003 |
1004 def searchstate_selector(cls, req, rset, row=None, col=0, **kwargs): |
1004 def searchstate_selector(cls, req, rset=None, row=None, col=0, **kwargs): |
1005 return match_search_state(cls.search_states)(cls, req, rset, row, col) |
1005 return match_search_state(cls.search_states)(cls, req, rset, row, col) |
1006 searchstate_selector = deprecated_function(searchstate_selector) |
1006 searchstate_selector = deprecated_function(searchstate_selector) |
1007 |
1007 |
1008 def match_user_group(cls, req, rset=None, row=None, col=0, **kwargs): |
1008 def match_user_group(cls, req, rset=None, row=None, col=0, **kwargs): |
1009 return match_user_groups(*cls.require_groups)(cls, req, rset, row, col, **kwargs) |
1009 return match_user_groups(*cls.require_groups)(cls, req, rset, row, col, **kwargs) |
1010 in_group_selector = deprecated_function(match_user_group) |
1010 in_group_selector = deprecated_function(match_user_group) |
1011 match_user_group = deprecated_function(match_user_group) |
1011 match_user_group = deprecated_function(match_user_group) |
1012 |
1012 |
1013 def has_relation(cls, req, rset, row=None, col=0, **kwargs): |
1013 def has_relation(cls, req, rset=None, row=None, col=0, **kwargs): |
1014 return relation_possible(cls.rtype, role(cls), cls.etype, |
1014 return relation_possible(cls.rtype, role(cls), cls.etype, |
1015 getattr(cls, 'require_permission', 'read'))(cls, req, rset, row, col, **kwargs) |
1015 getattr(cls, 'require_permission', 'read'))(cls, req, rset, row, col, **kwargs) |
1016 has_relation = deprecated_function(has_relation) |
1016 has_relation = deprecated_function(has_relation) |
1017 |
1017 |
1018 def one_has_relation(cls, req, rset, row=None, col=0, **kwargs): |
1018 def one_has_relation(cls, req, rset=None, row=None, col=0, **kwargs): |
1019 return relation_possible(cls.rtype, role(cls), cls.etype, |
1019 return relation_possible(cls.rtype, role(cls), cls.etype, |
1020 getattr(cls, 'require_permission', 'read', |
1020 getattr(cls, 'require_permission', 'read', |
1021 once_is_enough=True))(cls, req, rset, row, col, **kwargs) |
1021 once_is_enough=True))(cls, req, rset, row, col, **kwargs) |
1022 one_has_relation = deprecated_function(one_has_relation, 'use relation_possible selector') |
1022 one_has_relation = deprecated_function(one_has_relation, 'use relation_possible selector') |
1023 |
1023 |
1024 def accept_rset(cls, req, rset, row=None, col=0, **kwargs): |
1024 def accept_rset(cls, req, rset=None, row=None, col=0, **kwargs): |
1025 """simply delegate to cls.accept_rset method""" |
1025 """simply delegate to cls.accept_rset method""" |
1026 return implements(*cls.accepts)(cls, req, rset, row=row, col=col) |
1026 return implements(*cls.accepts)(cls, req, rset, row=row, col=col) |
1027 accept_rset_selector = deprecated_function(accept_rset) |
1027 accept_rset_selector = deprecated_function(accept_rset) |
1028 accept_rset = deprecated_function(accept_rset, 'use implements selector') |
1028 accept_rset = deprecated_function(accept_rset, 'use implements selector') |
1029 |
1029 |
1034 accept_one = deprecated_function(chainall(one_line_rset, accept, |
1034 accept_one = deprecated_function(chainall(one_line_rset, accept, |
1035 name='accept_one')) |
1035 name='accept_one')) |
1036 accept_one_selector = deprecated_function(accept_one) |
1036 accept_one_selector = deprecated_function(accept_one) |
1037 |
1037 |
1038 |
1038 |
1039 def _rql_condition(cls, req, rset, row=None, col=0, **kwargs): |
1039 def _rql_condition(cls, req, rset=None, row=None, col=0, **kwargs): |
1040 if cls.condition: |
1040 if cls.condition: |
1041 return rql_condition(cls.condition)(cls, req, rset, row, col) |
1041 return rql_condition(cls.condition)(cls, req, rset, row, col) |
1042 return 1 |
1042 return 1 |
1043 _rqlcondition_selector = deprecated_function(_rql_condition) |
1043 _rqlcondition_selector = deprecated_function(_rql_condition) |
1044 |
1044 |
1045 rqlcondition_selector = deprecated_function(chainall(non_final_entity(), one_line_rset, _rql_condition, |
1045 rqlcondition_selector = deprecated_function(chainall(non_final_entity(), one_line_rset, _rql_condition, |
1046 name='rql_condition')) |
1046 name='rql_condition')) |
1047 |
1047 |
1048 def but_etype_selector(cls, req, rset, row=None, col=0, **kwargs): |
1048 def but_etype_selector(cls, req, rset=None, row=None, col=0, **kwargs): |
1049 return but_etype(cls.etype)(cls, req, rset, row, col) |
1049 return but_etype(cls.etype)(cls, req, rset, row, col) |
1050 but_etype_selector = deprecated_function(but_etype_selector) |
1050 but_etype_selector = deprecated_function(but_etype_selector) |
1051 |
1051 |
1052 @lltrace |
1052 @lltrace |
1053 def etype_rtype_selector(cls, req, rset, row=None, col=0, **kwargs): |
1053 def etype_rtype_selector(cls, req, rset=None, row=None, col=0, **kwargs): |
1054 schema = cls.schema |
1054 schema = cls.schema |
1055 perm = getattr(cls, 'require_permission', 'read') |
1055 perm = getattr(cls, 'require_permission', 'read') |
1056 if hasattr(cls, 'etype'): |
1056 if hasattr(cls, 'etype'): |
1057 eschema = schema.eschema(cls.etype) |
1057 eschema = schema.eschema(cls.etype) |
1058 if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)): |
1058 if not (eschema.has_perm(req, perm) or eschema.has_local_role(perm)): |