web/action.py
branchtls-sprint
changeset 742 99115e029dca
parent 722 50a99184cf47
child 753 17d38f000bea
equal deleted inserted replaced
739:39721e56b56d 742:99115e029dca
     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 import role, target
     9 from cubicweb import role, target
       
    10 from cubicweb.vregistry import objectify_selector
    10 from cubicweb.selectors import (relation_possible, match_search_state,
    11 from cubicweb.selectors import (relation_possible, match_search_state,
    11                                 one_line_rset, may_add_relation, yes,
    12                                 one_line_rset, may_add_relation, yes,
    12                                 accepts_compat, condition_compat, deprecate)
    13                                 accepts_compat, condition_compat, deprecate)
    13 from cubicweb.appobject import AppRsetObject
    14 from cubicweb.appobject import AppRsetObject
    14 from cubicweb.common.registerers import accepts_registerer
    15 from cubicweb.common.registerers import accepts_registerer
    20     """abstract action. Handle the .search_states attribute to match
    21     """abstract action. Handle the .search_states attribute to match
    21     request search state. 
    22     request search state. 
    22     """
    23     """
    23     __registry__ = 'actions'
    24     __registry__ = 'actions'
    24     __registerer__ = accepts_registerer
    25     __registerer__ = accepts_registerer
    25     __selectors__ = (yes,) 
    26     __select__ = yes()
    26     
    27     
    27     property_defs = {
    28     property_defs = {
    28         'visible':  dict(type='Boolean', default=True,
    29         'visible':  dict(type='Boolean', default=True,
    29                          help=_('display the action or not')),
    30                          help=_('display the action or not')),
    30         'order':    dict(type='Int', default=99,
    31         'order':    dict(type='Int', default=99,
    70     with an initial relation set to an entity.
    71     with an initial relation set to an entity.
    71     Additionaly to EntityAction behaviour, this class is parametrized
    72     Additionaly to EntityAction behaviour, this class is parametrized
    72     using .etype, .rtype and .target attributes to check if the
    73     using .etype, .rtype and .target attributes to check if the
    73     action apply and if the logged user has access to it
    74     action apply and if the logged user has access to it
    74     """
    75     """
       
    76     @objectify_selector
    75     def my_selector(cls, req, rset, row=None, col=0, **kwargs):
    77     def my_selector(cls, req, rset, row=None, col=0, **kwargs):
    76         selector = (match_search_state('normal') & one_line_rset
    78         selector = (match_search_state('normal') & one_line_rset
    77                     & relation_possible(cls.rtype, role(cls), cls.etype,
    79                     & relation_possible(cls.rtype, role(cls), cls.etype,
    78                                         action='add')
    80                                         action='add')
    79                     & may_add_relation(cls.rtype, role(cls)))
    81                     & may_add_relation(cls.rtype, role(cls)))
    80         return selector(cls, req, rset, row, col, **kwargs)
    82         return selector(cls, req, rset, row, col, **kwargs)
    81 
    83 
    82     __selectors__ = (my_selector,)
    84     __select__ = my_selector()
    83     registered = accepts_compat(Action.registered.im_func)
    85     registered = accepts_compat(Action.registered.im_func)
    84     
    86     
    85     category = 'addrelated'
    87     category = 'addrelated'
    86                 
    88                 
    87     def url(self):
    89     def url(self):