author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 26 Aug 2009 14:45:56 +0200 | |
changeset 3023 | 7864fee8b4ec |
parent 2890 | fdcb8a2bb6eb |
child 3230 | 1d25e928c299 |
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 |
} |
|
34 |
site_wide = True # don't want user to configuration actions eproperties |
|
35 |
category = 'moreactions' |
|
1433 | 36 |
|
0 | 37 |
def url(self): |
38 |
"""return the url associated with this action""" |
|
39 |
raise NotImplementedError |
|
1433 | 40 |
|
0 | 41 |
def html_class(self): |
42 |
if self.req.selected(self.url()): |
|
43 |
return 'selected' |
|
44 |
if self.category: |
|
45 |
return 'box' + self.category.capitalize() |
|
46 |
||
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
|
47 |
|
0 | 48 |
class UnregisteredAction(Action): |
49 |
"""non registered action used to build boxes. Unless you set them |
|
50 |
explicitly, .vreg and .schema attributes at least are None. |
|
51 |
""" |
|
52 |
category = None |
|
53 |
id = None |
|
1433 | 54 |
|
0 | 55 |
def __init__(self, req, rset, title, path, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
56 |
Action.__init__(self, req, rset=rset) |
0 | 57 |
self.title = req._(title) |
58 |
self._path = path |
|
59 |
self.__dict__.update(kwargs) |
|
1433 | 60 |
|
0 | 61 |
def url(self): |
62 |
return self._path |
|
63 |
||
64 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
65 |
class LinkToEntityAction(Action): |
0 | 66 |
"""base class for actions consisting to create a new object |
67 |
with an initial relation set to an entity. |
|
68 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
69 |
using .etype, .rtype and .target attributes to check if the |
|
70 |
action apply and if the logged user has access to it |
|
71 |
""" |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
72 |
__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
|
73 |
& partial_relation_possible(action='add') |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
74 |
& partial_may_add_relation()) |
0 | 75 |
category = 'addrelated' |
1433 | 76 |
|
0 | 77 |
def url(self): |
78 |
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
|
79 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 80 |
return self.build_url(vid='creation', etype=self.etype, |
81 |
__linkto=linkto, |
|
82 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
83 |
__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
|
84 |