8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 _ = unicode |
9 _ = unicode |
10 |
10 |
11 from cubicweb import target |
11 from cubicweb import target |
12 from cubicweb.selectors import (partial_relation_possible, match_search_state, |
12 from cubicweb.selectors import (partial_relation_possible, match_search_state, |
13 one_line_rset, partial_may_add_relation, yes, |
13 one_line_rset, partial_may_add_relation, yes) |
14 accepts_compat, condition_compat, deprecate) |
|
15 from cubicweb.appobject import AppObject |
14 from cubicweb.appobject import AppObject |
16 |
15 |
17 |
16 |
18 class Action(AppObject): |
17 class Action(AppObject): |
19 """abstract action. Handle the .search_states attribute to match |
18 """abstract action. Handle the .search_states attribute to match |
71 action apply and if the logged user has access to it |
70 action apply and if the logged user has access to it |
72 """ |
71 """ |
73 __select__ = (match_search_state('normal') & one_line_rset() |
72 __select__ = (match_search_state('normal') & one_line_rset() |
74 & partial_relation_possible(action='add') |
73 & partial_relation_possible(action='add') |
75 & partial_may_add_relation()) |
74 & partial_may_add_relation()) |
76 registered = accepts_compat(Action.registered) |
|
77 |
|
78 category = 'addrelated' |
75 category = 'addrelated' |
79 |
76 |
80 def url(self): |
77 def url(self): |
81 current_entity = self.rset.get_entity(self.row or 0, self.col or 0) |
78 current_entity = self.rset.get_entity(self.row or 0, self.col or 0) |
82 linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
79 linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
83 return self.build_url(vid='creation', etype=self.etype, |
80 return self.build_url(vid='creation', etype=self.etype, |
84 __linkto=linkto, |
81 __linkto=linkto, |
85 __redirectpath=current_entity.rest_path(), # should not be url quoted! |
82 __redirectpath=current_entity.rest_path(), # should not be url quoted! |
86 __redirectvid=self.req.form.get('__redirectvid', '')) |
83 __redirectvid=self.req.form.get('__redirectvid', '')) |
87 |
84 |
88 class EntityAction(Action): |
|
89 """DEPRECATED / BACKWARD COMPAT |
|
90 """ |
|
91 registered = deprecate(condition_compat(accepts_compat(Action.registered)), |
|
92 msg='EntityAction is deprecated, use Action with ' |
|
93 'appropriate selectors') |
|
94 |
|