author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 30 Sep 2009 18:57:42 +0200 | |
changeset 3536 | f6c9a5df80fb |
parent 3460 | e4843535db25 |
child 4252 | 6c4f109c2b03 |
permissions | -rw-r--r-- |
0 | 1 |
"""abstract action classes for CubicWeb web client |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1536
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1536
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
2698 | 9 |
_ = unicode |
0 | 10 |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
11 |
from cubicweb import target |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
12 |
from cubicweb.selectors import (partial_relation_possible, match_search_state, |
2819
b864288fd316
remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2799
diff
changeset
|
13 |
one_line_rset, partial_may_add_relation, yes) |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
14 |
from cubicweb.appobject import AppObject |
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
15 |
|
0 | 16 |
|
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
17 |
class Action(AppObject): |
0 | 18 |
"""abstract action. Handle the .search_states attribute to match |
1433 | 19 |
request search state. |
0 | 20 |
""" |
21 |
__registry__ = 'actions' |
|
1536
1e695b78d085
match normal search state on action by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
22 |
__select__ = match_search_state('normal') |
1433 | 23 |
|
2799
b703639614e7
refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
24 |
cw_property_defs = { |
0 | 25 |
'visible': dict(type='Boolean', default=True, |
26 |
help=_('display the action or not')), |
|
27 |
'order': dict(type='Int', default=99, |
|
28 |
help=_('display order of the action')), |
|
29 |
'category': dict(type='String', default='moreactions', |
|
30 |
vocabulary=('mainactions', 'moreactions', 'addrelated', |
|
31 |
'useractions', 'siteactions', 'hidden'), |
|
32 |
help=_('context where this component should be displayed')), |
|
33 |
} |
|
3220
11b6016e3970
cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3219
diff
changeset
|
34 |
site_wide = True # don't want user to configurate actions |
0 | 35 |
category = 'moreactions' |
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
36 |
# actions in category 'moreactions' can specify a sub-menu in which they should be filed |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
37 |
submenu = None |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
38 |
|
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
39 |
def actual_actions(self): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
40 |
yield self |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
41 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
42 |
def fill_menu(self, box, menu): |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
43 |
"""add action(s) to the given submenu of the given box""" |
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
44 |
for action in self.actual_actions(): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
45 |
menu.append(box.box_action(action)) |
1433 | 46 |
|
0 | 47 |
def url(self): |
48 |
"""return the url associated with this action""" |
|
49 |
raise NotImplementedError |
|
1433 | 50 |
|
0 | 51 |
def html_class(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
52 |
if self._cw.selected(self.url()): |
0 | 53 |
return 'selected' |
54 |
if self.category: |
|
55 |
return 'box' + self.category.capitalize() |
|
56 |
||
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
57 |
def build_action(self, title, path, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
58 |
return UnregisteredAction(self._cw, self.cw_rset, title, path, **kwargs) |
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
59 |
|
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
254
diff
changeset
|
60 |
|
0 | 61 |
class UnregisteredAction(Action): |
62 |
"""non registered action used to build boxes. Unless you set them |
|
63 |
explicitly, .vreg and .schema attributes at least are None. |
|
64 |
""" |
|
65 |
category = None |
|
66 |
id = None |
|
1433 | 67 |
|
0 | 68 |
def __init__(self, req, rset, title, path, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
69 |
Action.__init__(self, req, rset=rset) |
0 | 70 |
self.title = req._(title) |
71 |
self._path = path |
|
72 |
self.__dict__.update(kwargs) |
|
1433 | 73 |
|
0 | 74 |
def url(self): |
75 |
return self._path |
|
76 |
||
77 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
78 |
class LinkToEntityAction(Action): |
0 | 79 |
"""base class for actions consisting to create a new object |
80 |
with an initial relation set to an entity. |
|
81 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
82 |
using .etype, .rtype and .target attributes to check if the |
|
83 |
action apply and if the logged user has access to it |
|
84 |
""" |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
85 |
__select__ = (match_search_state('normal') & one_line_rset() |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
86 |
& partial_relation_possible(action='add') |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
87 |
& partial_may_add_relation()) |
1433 | 88 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
89 |
submenu = 'addrelated' |
1433 | 90 |
|
0 | 91 |
def url(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
92 |
current_entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
631
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
254
diff
changeset
|
93 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
94 |
return self._cw.build_url('add/%s' % self.etype, __linkto=linkto, |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
95 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
96 |
__redirectvid=self._cw.form.get('__redirectvid', '')) |
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
97 |