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, yes) |
14 from cubicweb.appobject import AppObject |
14 from cubicweb.appobject import AppObject |
15 |
15 |
16 |
16 |
17 class Action(AppObject): |
17 class Action(AppObject): |
18 """abstract action. Handle the .search_states attribute to match |
18 """abstract action. Handle the .search_states attribute to match |
74 def url(self): |
74 def url(self): |
75 return self._path |
75 return self._path |
76 |
76 |
77 |
77 |
78 class LinkToEntityAction(Action): |
78 class LinkToEntityAction(Action): |
79 """base class for actions consisting to create a new object |
79 """base class for actions consisting to create a new object with an initial |
80 with an initial relation set to an entity. |
80 relation set to an entity. |
81 Additionaly to EntityAction behaviour, this class is parametrized |
81 |
82 using .etype, .rtype and .target attributes to check if the |
82 Additionaly to EntityAction behaviour, this class is parametrized using |
83 action apply and if the logged user has access to it |
83 .rtype, .role and .target_etype attributes to check if the action apply and |
|
84 if the logged user has access to it (see |
|
85 :class:`~cubicweb.selectors.partial_relation_possible` selector |
|
86 documentation for more information). |
84 """ |
87 """ |
85 __select__ = (match_search_state('normal') & one_line_rset() |
88 __select__ = (match_search_state('normal') & one_line_rset() |
86 & partial_relation_possible(action='add') |
89 & partial_relation_possible(action='add', strict=True)) |
87 & partial_may_add_relation()) |
|
88 |
90 |
89 submenu = 'addrelated' |
91 submenu = 'addrelated' |
90 |
92 |
91 def url(self): |
93 def url(self): |
92 current_entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
94 try: |
93 linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
95 ttype = self.etype # deprecated in 3.6, already warned by the selector |
94 return self._cw.build_url('add/%s' % self.etype, __linkto=linkto, |
96 except AttributeError: |
95 __redirectpath=current_entity.rest_path(), # should not be url quoted! |
97 ttype = self.target_etype |
|
98 entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
|
99 linkto = '%s:%s:%s' % (self.rtype, entity.eid, target(self)) |
|
100 return self._cw.build_url('add/%s' % ttype, __linkto=linkto, |
|
101 __redirectpath=entity.rest_path(), |
96 __redirectvid=self._cw.form.get('__redirectvid', '')) |
102 __redirectvid=self._cw.form.get('__redirectvid', '')) |
97 |
103 |