author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Thu, 19 Nov 2009 17:06:46 +0100 | |
branch | stable |
changeset 3880 | 88fc53eb5b5f |
parent 3272 | f46f2082468b |
child 3293 | 69c0ba095536 |
child 4212 | ab6573088b4a |
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, |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
13 |
one_line_rset, partial_may_add_relation, yes, |
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
14 |
accepts_compat, condition_compat, deprecate) |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
15 |
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
|
16 |
|
0 | 17 |
|
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
18 |
class Action(AppObject): |
0 | 19 |
"""abstract action. Handle the .search_states attribute to match |
1433 | 20 |
request search state. |
0 | 21 |
""" |
22 |
__registry__ = 'actions' |
|
1536
1e695b78d085
match normal search state on action by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
23 |
__select__ = match_search_state('normal') |
1433 | 24 |
|
0 | 25 |
property_defs = { |
26 |
'visible': dict(type='Boolean', default=True, |
|
27 |
help=_('display the action or not')), |
|
28 |
'order': dict(type='Int', default=99, |
|
29 |
help=_('display order of the action')), |
|
30 |
'category': dict(type='String', default='moreactions', |
|
31 |
vocabulary=('mainactions', 'moreactions', 'addrelated', |
|
32 |
'useractions', 'siteactions', 'hidden'), |
|
33 |
help=_('context where this component should be displayed')), |
|
34 |
} |
|
3220
11b6016e3970
cleanup, futur warning fixes :)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3219
diff
changeset
|
35 |
site_wide = True # don't want user to configurate actions |
0 | 36 |
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
|
37 |
# 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
|
38 |
submenu = None |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
39 |
|
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
|
40 |
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
|
41 |
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
|
42 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
43 |
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
|
44 |
"""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
|
45 |
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
|
46 |
menu.append(box.box_action(action)) |
1433 | 47 |
|
0 | 48 |
def url(self): |
49 |
"""return the url associated with this action""" |
|
50 |
raise NotImplementedError |
|
1433 | 51 |
|
0 | 52 |
def html_class(self): |
53 |
if self.req.selected(self.url()): |
|
54 |
return 'selected' |
|
55 |
if self.category: |
|
56 |
return 'box' + self.category.capitalize() |
|
57 |
||
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
|
58 |
def build_action(self, title, path, **kwargs): |
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 |
return UnregisteredAction(self.req, self.rset, title, path, **kwargs) |
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
|
60 |
|
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
|
61 |
|
0 | 62 |
class UnregisteredAction(Action): |
63 |
"""non registered action used to build boxes. Unless you set them |
|
64 |
explicitly, .vreg and .schema attributes at least are None. |
|
65 |
""" |
|
66 |
category = None |
|
67 |
id = None |
|
1433 | 68 |
|
0 | 69 |
def __init__(self, req, rset, title, path, **kwargs): |
70 |
Action.__init__(self, req, rset) |
|
71 |
self.title = req._(title) |
|
72 |
self._path = path |
|
73 |
self.__dict__.update(kwargs) |
|
1433 | 74 |
|
0 | 75 |
def url(self): |
76 |
return self._path |
|
77 |
||
78 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
79 |
class LinkToEntityAction(Action): |
0 | 80 |
"""base class for actions consisting to create a new object |
81 |
with an initial relation set to an entity. |
|
82 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
83 |
using .etype, .rtype and .target attributes to check if the |
|
84 |
action apply and if the logged user has access to it |
|
85 |
""" |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
86 |
__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
|
87 |
& partial_relation_possible(action='add') |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
88 |
& partial_may_add_relation()) |
757
01740274e774
remove explicit access to .im_func when overriding `registered`
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
753
diff
changeset
|
89 |
registered = accepts_compat(Action.registered) |
1433 | 90 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
91 |
submenu = 'addrelated' |
1433 | 92 |
|
0 | 93 |
def url(self): |
94 |
current_entity = self.rset.get_entity(self.row or 0, self.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
|
95 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
3272
f46f2082468b
nicer add urls
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3228
diff
changeset
|
96 |
return self.build_url('add/%s' % self.etype, __linkto=linkto, |
0 | 97 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
98 |
__redirectvid=self.req.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
|
99 |
|
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
100 |
class EntityAction(Action): |
768
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
101 |
"""DEPRECATED / BACKWARD COMPAT |
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
102 |
""" |
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
103 |
registered = deprecate(condition_compat(accepts_compat(Action.registered)), |
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
104 |
msg='EntityAction is deprecated, use Action with ' |
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
105 |
'appropriate selectors') |
1433 | 106 |