author | sylvain.thenault@logilab.fr |
Wed, 29 Apr 2009 10:46:08 +0200 | |
branch | tls-sprint |
changeset 1534 | 7edc063e8a91 |
parent 1433 | 091ac3ba5d51 |
child 1536 | 1e695b78d085 |
permissions | -rw-r--r-- |
0 | 1 |
"""abstract action classes for CubicWeb web client |
2 |
||
3 |
:organization: Logilab |
|
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
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
6 |
""" |
|
7 |
__docformat__ = "restructuredtext en" |
|
8 |
||
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
9 |
from cubicweb import target |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
10 |
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
|
11 |
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
|
12 |
accepts_compat, condition_compat, deprecate) |
722 | 13 |
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
|
14 |
|
0 | 15 |
_ = unicode |
16 |
||
17 |
||
18 |
class Action(AppRsetObject): |
|
19 |
"""abstract action. Handle the .search_states attribute to match |
|
1433 | 20 |
request search state. |
0 | 21 |
""" |
22 |
__registry__ = 'actions' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
23 |
__select__ = yes() |
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 |
} |
|
35 |
site_wide = True # don't want user to configuration actions eproperties |
|
36 |
category = 'moreactions' |
|
1433 | 37 |
|
0 | 38 |
def url(self): |
39 |
"""return the url associated with this action""" |
|
40 |
raise NotImplementedError |
|
1433 | 41 |
|
0 | 42 |
def html_class(self): |
43 |
if self.req.selected(self.url()): |
|
44 |
return 'selected' |
|
45 |
if self.category: |
|
46 |
return 'box' + self.category.capitalize() |
|
47 |
||
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
|
48 |
|
0 | 49 |
class UnregisteredAction(Action): |
50 |
"""non registered action used to build boxes. Unless you set them |
|
51 |
explicitly, .vreg and .schema attributes at least are None. |
|
52 |
""" |
|
53 |
category = None |
|
54 |
id = None |
|
1433 | 55 |
|
0 | 56 |
def __init__(self, req, rset, title, path, **kwargs): |
57 |
Action.__init__(self, req, rset) |
|
58 |
self.title = req._(title) |
|
59 |
self._path = path |
|
60 |
self.__dict__.update(kwargs) |
|
1433 | 61 |
|
0 | 62 |
def url(self): |
63 |
return self._path |
|
64 |
||
65 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
66 |
class LinkToEntityAction(Action): |
0 | 67 |
"""base class for actions consisting to create a new object |
68 |
with an initial relation set to an entity. |
|
69 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
70 |
using .etype, .rtype and .target attributes to check if the |
|
71 |
action apply and if the logged user has access to it |
|
72 |
""" |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
73 |
__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
|
74 |
& partial_relation_possible(action='add') |
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
75 |
& 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
|
76 |
registered = accepts_compat(Action.registered) |
1433 | 77 |
|
0 | 78 |
category = 'addrelated' |
1433 | 79 |
|
0 | 80 |
def url(self): |
81 |
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
|
82 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 83 |
return self.build_url(vid='creation', etype=self.etype, |
84 |
__linkto=linkto, |
|
85 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
86 |
__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
|
87 |
|
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
88 |
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
|
89 |
"""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
|
90 |
""" |
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
'appropriate selectors') |
1433 | 94 |