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