author | sylvain.thenault@logilab.fr |
Wed, 18 Feb 2009 00:30:55 +0100 | |
branch | tls-sprint |
changeset 736 | 18c940e3f98d |
parent 722 | 50a99184cf47 |
child 742 | 99115e029dca |
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 |
||
652
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
9 |
from cubicweb import role, target |
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
10 |
from cubicweb.selectors import (relation_possible, match_search_state, |
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
11 |
one_line_rset, may_add_relation, yes, |
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 |
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
25 |
__selectors__ = (yes,) |
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 |
""" |
|
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
|
75 |
def my_selector(cls, req, rset, row=None, col=0, **kwargs): |
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
76 |
selector = (match_search_state('normal') & one_line_rset |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
77 |
& relation_possible(cls.rtype, role(cls), cls.etype, |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
78 |
action='add') |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
79 |
& may_add_relation(cls.rtype, role(cls))) |
652
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
80 |
return selector(cls, req, rset, row, col, **kwargs) |
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
81 |
|
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
82 |
__selectors__ = (my_selector,) |
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
83 |
registered = accepts_compat(Action.registered.im_func) |
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 |
|
0 | 85 |
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
|
86 |
|
0 | 87 |
def url(self): |
88 |
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
|
89 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 90 |
return self.build_url(vid='creation', etype=self.etype, |
91 |
__linkto=linkto, |
|
92 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
93 |
__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
|
94 |
|
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
95 |
class EntityAction(Action): |
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
96 |
"""DEPRECATED / BACKWARD COMPAT |
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
97 |
""" |
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
98 |
registered = deprecate(accepts_compat(condition_compat(Action.registered)), |
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
99 |
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
|
100 |
'appropriate selectors') |
0 | 101 |