author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Wed, 18 Feb 2009 11:35:54 +0100 | |
branch | tls-sprint |
changeset 768 | 878e6139a46b |
parent 767 | b094cf8535b4 |
child 782 | 01801a10c567 |
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 |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
10 |
from cubicweb.vregistry import objectify_selector |
652
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
11 |
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
|
12 |
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
|
13 |
accepts_compat, condition_compat, deprecate) |
722 | 14 |
from cubicweb.appobject import AppRsetObject |
670 | 15 |
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
|
16 |
|
0 | 17 |
_ = unicode |
18 |
||
19 |
||
20 |
class Action(AppRsetObject): |
|
21 |
"""abstract action. Handle the .search_states attribute to match |
|
22 |
request search state. |
|
23 |
""" |
|
24 |
__registry__ = 'actions' |
|
670 | 25 |
__registerer__ = accepts_registerer |
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
26 |
__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
|
27 |
|
0 | 28 |
property_defs = { |
29 |
'visible': dict(type='Boolean', default=True, |
|
30 |
help=_('display the action or not')), |
|
31 |
'order': dict(type='Int', default=99, |
|
32 |
help=_('display order of the action')), |
|
33 |
'category': dict(type='String', default='moreactions', |
|
34 |
vocabulary=('mainactions', 'moreactions', 'addrelated', |
|
35 |
'useractions', 'siteactions', 'hidden'), |
|
36 |
help=_('context where this component should be displayed')), |
|
37 |
} |
|
38 |
site_wide = True # don't want user to configuration actions eproperties |
|
39 |
category = 'moreactions' |
|
40 |
||
41 |
def url(self): |
|
42 |
"""return the url associated with this action""" |
|
43 |
raise NotImplementedError |
|
44 |
||
45 |
def html_class(self): |
|
46 |
if self.req.selected(self.url()): |
|
47 |
return 'selected' |
|
48 |
if self.category: |
|
49 |
return 'box' + self.category.capitalize() |
|
50 |
||
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
|
51 |
|
0 | 52 |
class UnregisteredAction(Action): |
53 |
"""non registered action used to build boxes. Unless you set them |
|
54 |
explicitly, .vreg and .schema attributes at least are None. |
|
55 |
""" |
|
56 |
category = None |
|
57 |
id = None |
|
58 |
||
59 |
def __init__(self, req, rset, title, path, **kwargs): |
|
60 |
Action.__init__(self, req, rset) |
|
61 |
self.title = req._(title) |
|
62 |
self._path = path |
|
63 |
self.__dict__.update(kwargs) |
|
64 |
||
65 |
def url(self): |
|
66 |
return self._path |
|
67 |
||
68 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
69 |
class LinkToEntityAction(Action): |
0 | 70 |
"""base class for actions consisting to create a new object |
71 |
with an initial relation set to an entity. |
|
72 |
Additionaly to EntityAction behaviour, this class is parametrized |
|
73 |
using .etype, .rtype and .target attributes to check if the |
|
74 |
action apply and if the logged user has access to it |
|
75 |
""" |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
76 |
@objectify_selector |
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
|
77 |
def my_selector(cls, req, rset, row=None, col=0, **kwargs): |
753
17d38f000bea
some minor __select__ composition fixes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
742
diff
changeset
|
78 |
selector = (match_search_state('normal') & one_line_rset() |
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
79 |
& 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
|
80 |
action='add') |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
81 |
& 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
|
82 |
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
|
83 |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
84 |
__select__ = my_selector() |
757
01740274e774
remove explicit access to .im_func when overriding `registered`
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
753
diff
changeset
|
85 |
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
|
86 |
|
0 | 87 |
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
|
88 |
|
0 | 89 |
def url(self): |
90 |
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
|
91 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 92 |
return self.build_url(vid='creation', etype=self.etype, |
93 |
__linkto=linkto, |
|
94 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
95 |
__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
|
96 |
|
657
fd019f41aa2f
work in progress - fix deprecation of EntityAction - fix various selectors bugs
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
653
diff
changeset
|
97 |
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
|
98 |
"""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
|
99 |
""" |
878e6139a46b
fix compatibility class EntityAction: test for accepts() before has_condition()
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
767
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
'appropriate selectors') |
0 | 103 |