author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 28 May 2009 11:37:27 +0200 | |
changeset 1980 | 35394365b6c1 |
parent 1977 | 606923dff11b |
child 2656 | a93ae0f6c0ad |
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" |
|
9 |
||
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
10 |
from cubicweb import target |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
11 |
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
|
12 |
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
|
13 |
accepts_compat, condition_compat, deprecate) |
722 | 14 |
from cubicweb.appobject import AppRsetObject |
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 |
_ = unicode |
17 |
||
18 |
||
19 |
class Action(AppRsetObject): |
|
20 |
"""abstract action. Handle the .search_states attribute to match |
|
1433 | 21 |
request search state. |
0 | 22 |
""" |
23 |
__registry__ = 'actions' |
|
1536
1e695b78d085
match normal search state on action by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
24 |
__select__ = match_search_state('normal') |
1433 | 25 |
|
0 | 26 |
property_defs = { |
27 |
'visible': dict(type='Boolean', default=True, |
|
28 |
help=_('display the action or not')), |
|
29 |
'order': dict(type='Int', default=99, |
|
30 |
help=_('display order of the action')), |
|
31 |
'category': dict(type='String', default='moreactions', |
|
32 |
vocabulary=('mainactions', 'moreactions', 'addrelated', |
|
33 |
'useractions', 'siteactions', 'hidden'), |
|
34 |
help=_('context where this component should be displayed')), |
|
35 |
} |
|
36 |
site_wide = True # don't want user to configuration actions eproperties |
|
37 |
category = 'moreactions' |
|
1433 | 38 |
|
0 | 39 |
def url(self): |
40 |
"""return the url associated with this action""" |
|
41 |
raise NotImplementedError |
|
1433 | 42 |
|
0 | 43 |
def html_class(self): |
44 |
if self.req.selected(self.url()): |
|
45 |
return 'selected' |
|
46 |
if self.category: |
|
47 |
return 'box' + self.category.capitalize() |
|
48 |
||
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
|
49 |
|
0 | 50 |
class UnregisteredAction(Action): |
51 |
"""non registered action used to build boxes. Unless you set them |
|
52 |
explicitly, .vreg and .schema attributes at least are None. |
|
53 |
""" |
|
54 |
category = None |
|
55 |
id = None |
|
1433 | 56 |
|
0 | 57 |
def __init__(self, req, rset, title, path, **kwargs): |
58 |
Action.__init__(self, req, rset) |
|
59 |
self.title = req._(title) |
|
60 |
self._path = path |
|
61 |
self.__dict__.update(kwargs) |
|
1433 | 62 |
|
0 | 63 |
def url(self): |
64 |
return self._path |
|
65 |
||
66 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
67 |
class LinkToEntityAction(Action): |
0 | 68 |
"""base class for actions consisting to create a new object |
69 |
with an initial relation set to an entity. |
|
70 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
71 |
using .etype, .rtype and .target attributes to check if the |
|
72 |
action apply and if the logged user has access to it |
|
73 |
""" |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
74 |
__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
|
75 |
& partial_relation_possible(action='add') |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
76 |
& 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
|
77 |
registered = accepts_compat(Action.registered) |
1433 | 78 |
|
0 | 79 |
category = 'addrelated' |
1433 | 80 |
|
0 | 81 |
def url(self): |
82 |
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
|
83 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 84 |
return self.build_url(vid='creation', etype=self.etype, |
85 |
__linkto=linkto, |
|
86 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
87 |
__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
|
88 |
|
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
89 |
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
|
90 |
"""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
|
91 |
""" |
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
92 |
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
|
93 |
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
|
94 |
'appropriate selectors') |
1433 | 95 |