web/views/actions.py
changeset 8190 2a3c1b787688
parent 8128 0a927fe4541b
child 8267 486386d9f836
equal deleted inserted replaced
8189:2ee0ef069fa7 8190:2a3c1b787688
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    21 _ = unicode
    21 _ = unicode
    22 
    22 
    23 from warnings import warn
    23 from warnings import warn
    24 
    24 
    25 from logilab.mtconverter import xml_escape
    25 from logilab.mtconverter import xml_escape
       
    26 from logilab.common.registry import objectify_predicate, yes
    26 
    27 
    27 from cubicweb.schema import display_name
    28 from cubicweb.schema import display_name
    28 from cubicweb.appobject import objectify_selector
    29 from cubicweb.predicates import (EntityPredicate,
    29 from cubicweb.selectors import (EntitySelector, yes,
       
    30     one_line_rset, multi_lines_rset, one_etype_rset, relation_possible,
    30     one_line_rset, multi_lines_rset, one_etype_rset, relation_possible,
    31     nonempty_rset, non_final_entity, score_entity,
    31     nonempty_rset, non_final_entity, score_entity,
    32     authenticated_user, match_user_groups, match_search_state,
    32     authenticated_user, match_user_groups, match_search_state,
    33     has_permission, has_add_permission, is_instance, debug_mode,
    33     has_permission, has_add_permission, is_instance, debug_mode,
    34     )
    34     )
    35 from cubicweb.web import uicfg, controller, action
    35 from cubicweb.web import uicfg, controller, action
    36 from cubicweb.web.views import linksearch_select_url, vid_from_rset
    36 from cubicweb.web.views import linksearch_select_url, vid_from_rset
    37 
    37 
    38 
    38 
    39 class has_editable_relation(EntitySelector):
    39 class has_editable_relation(EntityPredicate):
    40     """accept if some relations for an entity found in the result set is
    40     """accept if some relations for an entity found in the result set is
    41     editable by the logged user.
    41     editable by the logged user.
    42 
    42 
    43     See `EntitySelector` documentation for behaviour when row is not specified.
    43     See `EntityPredicate` documentation for behaviour when row is not specified.
    44     """
    44     """
    45 
    45 
    46     def score_entity(self, entity):
    46     def score_entity(self, entity):
    47         # if user has no update right but it can modify some relation,
    47         # if user has no update right but it can modify some relation,
    48         # display action anyway
    48         # display action anyway
    53         editableattrs = form.editable_attributes(strict=True)
    53         editableattrs = form.editable_attributes(strict=True)
    54         for rschema, role in editableattrs:
    54         for rschema, role in editableattrs:
    55             return 1
    55             return 1
    56         return 0
    56         return 0
    57 
    57 
    58 @objectify_selector
    58 @objectify_predicate
    59 def match_searched_etype(cls, req, rset=None, **kwargs):
    59 def match_searched_etype(cls, req, rset=None, **kwargs):
    60     return req.match_search_state(rset)
    60     return req.match_search_state(rset)
    61 
    61 
    62 @objectify_selector
    62 @objectify_predicate
    63 def view_is_not_default_view(cls, req, rset=None, **kwargs):
    63 def view_is_not_default_view(cls, req, rset=None, **kwargs):
    64     # interesting if it propose another view than the current one
    64     # interesting if it propose another view than the current one
    65     vid = req.form.get('vid')
    65     vid = req.form.get('vid')
    66     if vid and vid != vid_from_rset(req, rset, req.vreg.schema):
    66     if vid and vid != vid_from_rset(req, rset, req.vreg.schema):
    67         return 1
    67         return 1
    68     return 0
    68     return 0
    69 
    69 
    70 @objectify_selector
    70 @objectify_predicate
    71 def addable_etype_empty_rset(cls, req, rset=None, **kwargs):
    71 def addable_etype_empty_rset(cls, req, rset=None, **kwargs):
    72     if rset is not None and not rset.rowcount:
    72     if rset is not None and not rset.rowcount:
    73         rqlst = rset.syntax_tree()
    73         rqlst = rset.syntax_tree()
    74         if len(rqlst.children) > 1:
    74         if len(rqlst.children) > 1:
    75             return 0
    75             return 0