# HG changeset patch # User sylvain.thenault@logilab.fr # Date 1238153124 -3600 # Node ID 8d9b705168d3357b92b5de527b9adba71c0b90d9 # Parent 7074698c6522b46585388add819b87237c47d8e9 actions specific selector diff -r 7074698c6522 -r 8d9b705168d3 selectors.py --- a/selectors.py Fri Mar 27 12:24:47 2009 +0100 +++ b/selectors.py Fri Mar 27 12:25:24 2009 +0100 @@ -655,26 +655,6 @@ self.target_etype = getattr(cls, 'etype', None) -class has_editable_relation(EntitySelector): - """accept if some relations for an entity found in the result set is - editable by the logged user. - - See `EntitySelector` documentation for behaviour when row is not specified. - """ - - def score_entity(self, entity): - # if user has no update right but it can modify some relation, - # display action anyway - for dummy in entity.srelations_by_category(('generic', 'metadata'), - 'add'): - return 1 - for rschema, targetschemas, role in entity.relations_by_category( - ('primary', 'secondary'), 'add'): - if not rschema.is_final(): - return 1 - return 0 - - class may_add_relation(EntitySelector): """accept if the relation can be added to an entity found in the result set by the logged user. diff -r 7074698c6522 -r 8d9b705168d3 web/views/actions.py --- a/web/views/actions.py Fri Mar 27 12:24:47 2009 +0100 +++ b/web/views/actions.py Fri Mar 27 12:25:24 2009 +0100 @@ -7,17 +7,38 @@ __docformat__ = "restructuredtext en" from cubicweb.vregistry import objectify_selector -from cubicweb.selectors import ( +from cubicweb.selectors import (EntitySelector, one_line_rset, two_lines_rset, one_etype_rset, relation_possible, non_final_entity, authenticated_user, match_user_groups, match_search_state, - has_editable_relation, has_permission, has_add_permission, + has_permission, has_add_permission, ) from cubicweb.web.action import Action from cubicweb.web.views import linksearch_select_url, vid_from_rset +from cubicweb.web.views.editforms import AutomaticEntityForm _ = unicode + +class has_editable_relation(EntitySelector): + """accept if some relations for an entity found in the result set is + editable by the logged user. + + See `EntitySelector` documentation for behaviour when row is not specified. + """ + + def score_entity(self, entity): + # if user has no update right but it can modify some relation, + # display action anyway + for dummy in AutomaticEntityForm.esrelations_by_category( + entity, 'generic', 'add'): + return 1 + for rschema, targetschemas, role in AutomaticEntityForm.erelations_by_category( + entity, ('primary', 'secondary'), 'add'): + if not rschema.is_final(): + return 1 + return 0 + @objectify_selector def match_searched_etype(cls, req, rset, **kwargs): return req.match_search_state(rset)