web/views/actions.py
branchtls-sprint
changeset 1178 8d9b705168d3
parent 1132 96752791c2b6
child 1263 01152fffd593
equal deleted inserted replaced
1177:7074698c6522 1178:8d9b705168d3
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 from cubicweb.vregistry import objectify_selector
     9 from cubicweb.vregistry import objectify_selector
    10 from cubicweb.selectors import (
    10 from cubicweb.selectors import (EntitySelector, 
    11     one_line_rset, two_lines_rset, one_etype_rset, relation_possible,
    11     one_line_rset, two_lines_rset, one_etype_rset, relation_possible,
    12     non_final_entity,
    12     non_final_entity,
    13     authenticated_user, match_user_groups, match_search_state,
    13     authenticated_user, match_user_groups, match_search_state,
    14     has_editable_relation, has_permission, has_add_permission,
    14     has_permission, has_add_permission,
    15     )
    15     )
    16 from cubicweb.web.action import Action
    16 from cubicweb.web.action import Action
    17 from cubicweb.web.views import linksearch_select_url, vid_from_rset
    17 from cubicweb.web.views import linksearch_select_url, vid_from_rset
       
    18 from cubicweb.web.views.editforms import AutomaticEntityForm
    18 
    19 
    19 _ = unicode
    20 _ = unicode
       
    21 
       
    22 
       
    23 class has_editable_relation(EntitySelector):
       
    24     """accept if some relations for an entity found in the result set is
       
    25     editable by the logged user.
       
    26 
       
    27     See `EntitySelector` documentation for behaviour when row is not specified.
       
    28     """
       
    29         
       
    30     def score_entity(self, entity):
       
    31         # if user has no update right but it can modify some relation,
       
    32         # display action anyway
       
    33         for dummy in AutomaticEntityForm.esrelations_by_category(
       
    34             entity, 'generic', 'add'):
       
    35             return 1
       
    36         for rschema, targetschemas, role in AutomaticEntityForm.erelations_by_category(
       
    37             entity, ('primary', 'secondary'), 'add'):
       
    38             if not rschema.is_final():
       
    39                 return 1
       
    40         return 0
    20 
    41 
    21 @objectify_selector
    42 @objectify_selector
    22 def match_searched_etype(cls, req, rset, **kwargs):
    43 def match_searched_etype(cls, req, rset, **kwargs):
    23     return req.match_search_state(rset)
    44     return req.match_search_state(rset)
    24 
    45