4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
4 :copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 target |
9 from cubicweb import role, target |
|
10 from cubicweb.vregistry import chainall |
|
11 from cubicweb.selectors import (relation_possible, match_search_state, |
|
12 one_line_rset, may_add_relation, |
|
13 accepts_compat) |
10 from cubicweb.common.appobject import AppRsetObject |
14 from cubicweb.common.appobject import AppRsetObject |
11 from cubicweb.common.registerers import action_registerer |
15 from cubicweb.common.registerers import action_registerer |
12 from cubicweb.common.selectors import user_can_add_etype, \ |
|
13 match_search_state, searchstate_accept_one |
|
14 |
|
15 _ = unicode |
16 _ = unicode |
16 |
17 |
17 |
18 |
18 class Action(AppRsetObject): |
19 class Action(AppRsetObject): |
19 """abstract action. Handle the .search_states attribute to match |
20 """abstract action. Handle the .search_states attribute to match |
76 Additionaly to EntityAction behaviour, this class is parametrized |
77 Additionaly to EntityAction behaviour, this class is parametrized |
77 using .etype, .rtype and .target attributes to check if the |
78 using .etype, .rtype and .target attributes to check if the |
78 action apply and if the logged user has access to it |
79 action apply and if the logged user has access to it |
79 """ |
80 """ |
80 def my_selector(cls, req, rset, row=None, col=0, **kwargs): |
81 def my_selector(cls, req, rset, row=None, col=0, **kwargs): |
81 return chainall(match_search_state('normal'), |
82 selector = chainall(match_search_state('normal'), |
82 one_line_rset, |
83 one_line_rset, |
83 relation_possible(cls.rtype, role(cls), cls.etype, |
84 relation_possible(cls.rtype, role(cls), cls.etype, |
84 permission='add'), |
85 permission='add'), |
85 may_add_relation(cls.rtype, role(cls))) |
86 may_add_relation(cls.rtype, role(cls))) |
|
87 return selector(cls, req, rset, row, col, **kwargs) |
|
88 |
86 __selectors__ = (my_selector,) |
89 __selectors__ = (my_selector,) |
87 registered = accepts_compat(Action.registered.im_func) |
90 registered = accepts_compat(Action.registered.im_func) |
88 |
91 |
89 category = 'addrelated' |
92 category = 'addrelated' |
90 |
93 |