author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 30 Apr 2010 14:34:56 +0200 | |
changeset 5447 | f29dafba250a |
parent 5426 | 0d4853a6e5ee |
child 5556 | 9ab2b4c74baf |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
2 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
3 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
4 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
5 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
6 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
7 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
8 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
9 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
12 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
13 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
14 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
15 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
16 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""abstract action classes for CubicWeb web client |
19 |
||
20 |
""" |
|
21 |
__docformat__ = "restructuredtext en" |
|
2698 | 22 |
_ = unicode |
0 | 23 |
|
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
24 |
from cubicweb import target |
838
f2c56312b03a
rename abstract_* selectors into partial_* + add docstrings
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
782
diff
changeset
|
25 |
from cubicweb.selectors import (partial_relation_possible, match_search_state, |
4719
aaed3f813ef8
kill dead/useless code as suggested by pylint
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4462
diff
changeset
|
26 |
one_line_rset) |
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
27 |
from cubicweb.appobject import AppObject |
653
189877d9547d
use & operator instead of chainall, deprecate EntityAction, fix relation_possible action argument
sylvain.thenault@logilab.fr
parents:
652
diff
changeset
|
28 |
|
0 | 29 |
|
2656
a93ae0f6c0ad
R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
30 |
class Action(AppObject): |
0 | 31 |
"""abstract action. Handle the .search_states attribute to match |
1433 | 32 |
request search state. |
0 | 33 |
""" |
34 |
__registry__ = 'actions' |
|
1536
1e695b78d085
match normal search state on action by default
sylvain.thenault@logilab.fr
parents:
1433
diff
changeset
|
35 |
__select__ = match_search_state('normal') |
5246
3246b1f88a18
[web] stop having actions configurable through cwproperties: this clutter site management and .po files for a useless fonctionnality (which, where and how actions are displayed is handled by code)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4719
diff
changeset
|
36 |
order = 99 |
0 | 37 |
category = 'moreactions' |
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
38 |
# actions in category 'moreactions' can specify a sub-menu in which they should be filed |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
39 |
submenu = None |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
40 |
|
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
41 |
def actual_actions(self): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
42 |
yield self |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
43 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
44 |
def fill_menu(self, box, menu): |
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
45 |
"""add action(s) to the given submenu of the given box""" |
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
46 |
for action in self.actual_actions(): |
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
47 |
menu.append(box.box_action(action)) |
1433 | 48 |
|
0 | 49 |
def url(self): |
50 |
"""return the url associated with this action""" |
|
51 |
raise NotImplementedError |
|
1433 | 52 |
|
0 | 53 |
def html_class(self): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
54 |
if self._cw.selected(self.url()): |
0 | 55 |
return 'selected' |
56 |
if self.category: |
|
57 |
return 'box' + self.category.capitalize() |
|
58 |
||
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
59 |
def build_action(self, title, path, **kwargs): |
3451
6b46d73823f5
[api] work in progress, use __regid__, cw_*, etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3293
diff
changeset
|
60 |
return UnregisteredAction(self._cw, self.cw_rset, title, path, **kwargs) |
3228
7b05b2709439
[actions] refactor: extract actual_actions from fill_menu to work with table filter form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3220
diff
changeset
|
61 |
|
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
|
62 |
|
0 | 63 |
class UnregisteredAction(Action): |
64 |
"""non registered action used to build boxes. Unless you set them |
|
65 |
explicitly, .vreg and .schema attributes at least are None. |
|
66 |
""" |
|
67 |
category = None |
|
68 |
id = None |
|
1433 | 69 |
|
0 | 70 |
def __init__(self, req, rset, title, path, **kwargs): |
2890
fdcb8a2bb6eb
fix __init__ parameters
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2819
diff
changeset
|
71 |
Action.__init__(self, req, rset=rset) |
0 | 72 |
self.title = req._(title) |
73 |
self._path = path |
|
74 |
self.__dict__.update(kwargs) |
|
1433 | 75 |
|
0 | 76 |
def url(self): |
77 |
return self._path |
|
78 |
||
79 |
||
640
8e64f12be69c
drop EntityAction usage in cw, upgrade rql_condition and friends
sylvain.thenault@logilab.fr
parents:
631
diff
changeset
|
80 |
class LinkToEntityAction(Action): |
4462
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
81 |
"""base class for actions consisting to create a new object with an initial |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
82 |
relation set to an entity. |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
83 |
|
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
84 |
Additionaly to EntityAction behaviour, this class is parametrized using |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
85 |
.rtype, .role and .target_etype attributes to check if the action apply and |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
86 |
if the logged user has access to it (see |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
87 |
:class:`~cubicweb.selectors.partial_relation_possible` selector |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
88 |
documentation for more information). |
0 | 89 |
""" |
782
01801a10c567
introduce abstract selectors to get rid of the my_selector() contagion
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
768
diff
changeset
|
90 |
__select__ = (match_search_state('normal') & one_line_rset() |
4462
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
91 |
& partial_relation_possible(action='add', strict=True)) |
1433 | 92 |
|
3219
be8cfc00ae04
edit box refactoring to gain more control by using actions
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2698
diff
changeset
|
93 |
submenu = 'addrelated' |
1433 | 94 |
|
0 | 95 |
def url(self): |
4462
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
96 |
try: |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
97 |
ttype = self.etype # deprecated in 3.6, already warned by the selector |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
98 |
except AttributeError: |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
99 |
ttype = self.target_etype |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
100 |
entity = self.cw_rset.get_entity(self.cw_row or 0, self.cw_col or 0) |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
101 |
linkto = '%s:%s:%s' % (self.rtype, entity.eid, target(self)) |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
102 |
return self._cw.build_url('add/%s' % ttype, __linkto=linkto, |
c57c8176b8c2
reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
103 |
__redirectpath=entity.rest_path(), |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
3451
diff
changeset
|
104 |
__redirectvid=self._cw.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
|
105 |