author | sylvain.thenault@logilab.fr |
Tue, 17 Feb 2009 13:26:24 +0100 | |
branch | tls-sprint |
changeset 654 | 36e87179e91d |
parent 653 | 189877d9547d |
child 657 | fd019f41aa2f |
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 |
||
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
9 |
from logilab.common.deprecation import class_moved |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
10 |
|
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 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
|
12 |
from cubicweb.selectors import (relation_possible, match_search_state, |
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
13 |
one_line_rset, may_add_relation, |
603c782dc092
various SyntaxErrors / missing import fixes + reorganization of the `registered` classmethod
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
651
diff
changeset
|
14 |
accepts_compat) |
0 | 15 |
from cubicweb.common.appobject import AppRsetObject |
16 |
from cubicweb.common.registerers import action_registerer |
|
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
17 |
|
0 | 18 |
_ = unicode |
19 |
||
20 |
||
21 |
class Action(AppRsetObject): |
|
22 |
"""abstract action. Handle the .search_states attribute to match |
|
23 |
request search state. |
|
24 |
""" |
|
25 |
__registry__ = 'actions' |
|
26 |
__registerer__ = action_registerer |
|
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
|
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 |
""" |
|
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
|
76 |
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
|
77 |
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
|
78 |
& 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
|
79 |
action='add') |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
80 |
& 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
|
81 |
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
|
82 |
|
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
83 |
__selectors__ = (my_selector,) |
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
84 |
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
|
85 |
|
0 | 86 |
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
|
87 |
|
0 | 88 |
def url(self): |
89 |
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
|
90 |
linkto = '%s:%s:%s' % (self.rtype, current_entity.eid, target(self)) |
0 | 91 |
return self.build_url(vid='creation', etype=self.etype, |
92 |
__linkto=linkto, |
|
93 |
__redirectpath=current_entity.rest_path(), # should not be url quoted! |
|
94 |
__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
|
95 |
|
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
96 |
|
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
97 |
EntityAction = class_moved('EntityAction', Action, |
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
98 |
'EntityAction is deprecated, use Action with appropriate selectors') |
0 | 99 |