author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 29 May 2009 14:04:06 +0200 | |
changeset 2002 | 031414d88003 |
parent 1977 | 606923dff11b |
child 2121 | 9a14e1ee0eab |
permissions | -rw-r--r-- |
0 | 1 |
"""Set of HTML base actions |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1829
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
0 | 5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1829
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
714
diff
changeset
|
10 |
from cubicweb.vregistry import objectify_selector |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
11 |
from cubicweb.selectors import (EntitySelector, |
1132 | 12 |
one_line_rset, two_lines_rset, one_etype_rset, relation_possible, |
1829
f54710fcdd62
avoid SelectAction selection to crash on startup views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1551
diff
changeset
|
13 |
nonempty_rset, non_final_entity, |
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:
554
diff
changeset
|
14 |
authenticated_user, match_user_groups, match_search_state, |
1178 | 15 |
has_permission, has_add_permission, |
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:
554
diff
changeset
|
16 |
) |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
17 |
from cubicweb.web.action import Action |
824
a5e6acffde30
merge, split baseviews (new csvexport, xmlrss and editviews modules)
sylvain.thenault@logilab.fr
parents:
822
diff
changeset
|
18 |
from cubicweb.web.views import linksearch_select_url, vid_from_rset |
1498
2c6eec0b46b9
fix imports, cleanup, repair some ajax calls
sylvain.thenault@logilab.fr
parents:
1465
diff
changeset
|
19 |
from cubicweb.web.views.autoform import AutomaticEntityForm |
0 | 20 |
|
21 |
_ = unicode |
|
22 |
||
1178 | 23 |
|
24 |
class has_editable_relation(EntitySelector): |
|
25 |
"""accept if some relations for an entity found in the result set is |
|
26 |
editable by the logged user. |
|
27 |
||
28 |
See `EntitySelector` documentation for behaviour when row is not specified. |
|
29 |
""" |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
30 |
|
1178 | 31 |
def score_entity(self, entity): |
32 |
# if user has no update right but it can modify some relation, |
|
33 |
# display action anyway |
|
34 |
for dummy in AutomaticEntityForm.esrelations_by_category( |
|
35 |
entity, 'generic', 'add'): |
|
36 |
return 1 |
|
37 |
for rschema, targetschemas, role in AutomaticEntityForm.erelations_by_category( |
|
38 |
entity, ('primary', 'secondary'), 'add'): |
|
39 |
if not rschema.is_final(): |
|
40 |
return 1 |
|
41 |
return 0 |
|
42 |
||
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
714
diff
changeset
|
43 |
@objectify_selector |
775 | 44 |
def match_searched_etype(cls, req, rset, **kwargs): |
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:
554
diff
changeset
|
45 |
return req.match_search_state(rset) |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
46 |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
714
diff
changeset
|
47 |
@objectify_selector |
775 | 48 |
def view_is_not_default_view(cls, req, rset, **kwargs): |
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:
554
diff
changeset
|
49 |
# interesting if it propose another view than the current one |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
50 |
vid = req.form.get('vid') |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
51 |
if vid and vid != vid_from_rset(req, rset, cls.schema): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
52 |
return 1 |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
53 |
return 0 |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
54 |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
714
diff
changeset
|
55 |
@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:
554
diff
changeset
|
56 |
def addable_etype_empty_rset(cls, req, rset, **kwargs): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
57 |
if rset is not None and not rset.rowcount: |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
58 |
rqlst = rset.syntax_tree() |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
59 |
if len(rqlst.children) > 1: |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
60 |
return 0 |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
61 |
select = rqlst.children[0] |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
62 |
if len(select.defined_vars) == 1 and len(select.solutions) == 1: |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
63 |
rset._searched_etype = select.solutions[0].itervalues().next() |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
64 |
eschema = cls.schema.eschema(rset._searched_etype) |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
65 |
if not (eschema.is_final() or eschema.is_subobject(strict=True)) \ |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
66 |
and eschema.has_perm(req, 'add'): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
67 |
return 1 |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
68 |
return 0 |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
69 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
70 |
# generic primary actions ##################################################### |
0 | 71 |
|
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:
554
diff
changeset
|
72 |
class SelectAction(Action): |
0 | 73 |
"""base class for link search actions. By default apply on |
74 |
any size entity result search it the current state is 'linksearch' |
|
75 |
if accept match. |
|
76 |
""" |
|
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:
554
diff
changeset
|
77 |
id = 'select' |
1829
f54710fcdd62
avoid SelectAction selection to crash on startup views
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1551
diff
changeset
|
78 |
__select__ = match_search_state('linksearch') & nonempty_rset() & match_searched_etype() |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
79 |
|
0 | 80 |
title = _('select') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
81 |
category = 'mainactions' |
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:
554
diff
changeset
|
82 |
order = 0 |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
83 |
|
0 | 84 |
def url(self): |
85 |
return linksearch_select_url(self.req, self.rset) |
|
86 |
||
87 |
||
88 |
class CancelSelectAction(Action): |
|
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:
554
diff
changeset
|
89 |
id = 'cancel' |
707 | 90 |
__select__ = match_search_state('linksearch') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
91 |
|
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:
554
diff
changeset
|
92 |
title = _('cancel select') |
0 | 93 |
category = 'mainactions' |
94 |
order = 10 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
95 |
|
0 | 96 |
def url(self): |
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:
554
diff
changeset
|
97 |
target, eid, r_type, searched_type = self.req.search_state[1] |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
98 |
return self.build_url(str(eid), |
0 | 99 |
vid='edition', __mode='normal') |
100 |
||
101 |
||
102 |
class ViewAction(Action): |
|
103 |
id = 'view' |
|
707 | 104 |
__select__ = (match_search_state('normal') & |
105 |
match_user_groups('users', 'managers') & |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
106 |
view_is_not_default_view() & |
707 | 107 |
non_final_entity()) |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
108 |
|
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:
554
diff
changeset
|
109 |
title = _('view') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
110 |
category = 'mainactions' |
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:
554
diff
changeset
|
111 |
order = 0 |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
112 |
|
0 | 113 |
def url(self): |
114 |
params = self.req.form.copy() |
|
115 |
params.pop('vid', None) |
|
116 |
params.pop('__message', None) |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
117 |
return self.build_url(self.req.relative_path(includeparams=False), |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
118 |
**params) |
0 | 119 |
|
120 |
||
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:
554
diff
changeset
|
121 |
class ModifyAction(Action): |
0 | 122 |
id = 'edit' |
707 | 123 |
__select__ = (match_search_state('normal') & |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
124 |
one_line_rset() & |
707 | 125 |
(has_permission('update') | has_editable_relation('add'))) |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
126 |
|
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:
554
diff
changeset
|
127 |
title = _('modify') |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
128 |
category = 'mainactions' |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
129 |
order = 10 |
0 | 130 |
|
131 |
def url(self): |
|
132 |
entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
133 |
return entity.absolute_url(vid='edition') |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
134 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
135 |
|
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:
554
diff
changeset
|
136 |
class MultipleEditAction(Action): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
137 |
id = 'muledit' # XXX get strange conflicts if id='edit' |
707 | 138 |
__select__ = (match_search_state('normal') & |
753
17d38f000bea
some minor __select__ composition fixes
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
728
diff
changeset
|
139 |
two_lines_rset() & one_etype_rset() & |
707 | 140 |
has_permission('update')) |
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:
554
diff
changeset
|
141 |
|
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
142 |
title = _('modify') |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
143 |
category = 'mainactions' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
144 |
order = 10 |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
145 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
146 |
def url(self): |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
147 |
return self.build_url('view', rql=self.rset.rql, vid='muledit') |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
148 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
149 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
150 |
# generic secondary actions ################################################### |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
151 |
|
690
ea613e8a5e4f
should add relation_possible selector only if require_permission is in the schema
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
152 |
class ManagePermissionsAction(Action): |
781
323656dd85a9
fix import, use non_final_entity instead of implements('Any')
sylvain.thenault@logilab.fr
parents:
775
diff
changeset
|
153 |
id = 'managepermission' |
822 | 154 |
__select__ = one_line_rset() & non_final_entity() & match_user_groups('managers') |
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:
554
diff
changeset
|
155 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
156 |
title = _('manage permissions') |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
157 |
category = 'moreactions' |
1551 | 158 |
order = 15 |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
159 |
|
707 | 160 |
@classmethod |
690
ea613e8a5e4f
should add relation_possible selector only if require_permission is in the schema
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
161 |
def registered(cls, vreg): |
710
766c881e101f
overridden `registered()` methods must call the base implementation
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
696
diff
changeset
|
162 |
super(ManagePermissionsAction, cls).registered(vreg) |
690
ea613e8a5e4f
should add relation_possible selector only if require_permission is in the schema
sylvain.thenault@logilab.fr
parents:
660
diff
changeset
|
163 |
if 'require_permission' in vreg.schema: |
822 | 164 |
cls.__select__ = (one_line_rset() & non_final_entity() & |
165 |
(match_user_groups('managers') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1263
diff
changeset
|
166 |
| relation_possible('require_permission', 'subject', 'CWPermission', |
822 | 167 |
action='add'))) |
707 | 168 |
return super(ManagePermissionsAction, cls).registered(vreg) |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
169 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
170 |
def url(self): |
1465
42f13c790f11
fix bug in actions: action.row/col might be None and can't be passed directly to rset.get_entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1452
diff
changeset
|
171 |
return self.rset.get_entity(self.row or 0, self.col or 0).absolute_url(vid='security') |
0 | 172 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
173 |
|
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:
554
diff
changeset
|
174 |
class DeleteAction(Action): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
175 |
id = 'delete' |
786 | 176 |
__select__ = has_permission('delete') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
177 |
|
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:
554
diff
changeset
|
178 |
title = _('delete') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
179 |
category = 'moreactions' |
0 | 180 |
order = 20 |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
181 |
|
0 | 182 |
def url(self): |
183 |
if len(self.rset) == 1: |
|
1465
42f13c790f11
fix bug in actions: action.row/col might be None and can't be passed directly to rset.get_entity
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1452
diff
changeset
|
184 |
entity = self.rset.get_entity(self.row or 0, self.col or 0) |
0 | 185 |
return self.build_url(entity.rest_path(), vid='deleteconf') |
186 |
return self.build_url(rql=self.rset.printable_rql(), vid='deleteconf') |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
187 |
|
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
188 |
|
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:
554
diff
changeset
|
189 |
class CopyAction(Action): |
99f5852f8604
major selector refactoring (mostly to avoid looking for select parameters on the target class), start accept / interface unification)
sylvain.thenault@logilab.fr
parents:
554
diff
changeset
|
190 |
id = 'copy' |
707 | 191 |
__select__ = one_line_rset() & has_permission('add') |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
192 |
|
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:
554
diff
changeset
|
193 |
title = _('copy') |
0 | 194 |
category = 'moreactions' |
195 |
order = 30 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
196 |
|
0 | 197 |
def url(self): |
198 |
entity = self.rset.get_entity(self.row or 0, self.col or 0) |
|
199 |
return entity.absolute_url(vid='copy') |
|
200 |
||
201 |
||
202 |
class AddNewAction(MultipleEditAction): |
|
203 |
"""when we're seeing more than one entity with the same type, propose to |
|
204 |
add a new one |
|
205 |
""" |
|
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:
554
diff
changeset
|
206 |
id = 'addentity' |
707 | 207 |
__select__ = (match_search_state('normal') & |
208 |
(addable_etype_empty_rset() |
|
728
a95b284150d1
first pass to use __select__ instead of __selectors__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
714
diff
changeset
|
209 |
| (two_lines_rset() & one_etype_rset & has_add_permission())) |
707 | 210 |
) |
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:
554
diff
changeset
|
211 |
|
0 | 212 |
category = 'moreactions' |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
213 |
order = 40 |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
214 |
|
0 | 215 |
@property |
216 |
def rsettype(self): |
|
217 |
if self.rset: |
|
218 |
return self.rset.description[0][0] |
|
219 |
return self.rset._searched_etype |
|
220 |
||
221 |
@property |
|
222 |
def title(self): |
|
223 |
return self.req.__('add a %s' % self.rsettype) # generated msgid |
|
224 |
||
225 |
def url(self): |
|
226 |
return self.build_url('add/%s' % self.rsettype) |
|
227 |
||
228 |
||
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
229 |
# logged user actions ######################################################### |
0 | 230 |
|
231 |
class UserPreferencesAction(Action): |
|
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:
554
diff
changeset
|
232 |
id = 'myprefs' |
707 | 233 |
__select__ = authenticated_user() |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
234 |
|
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:
554
diff
changeset
|
235 |
title = _('user preferences') |
0 | 236 |
category = 'useractions' |
237 |
order = 10 |
|
238 |
||
239 |
def url(self): |
|
240 |
return self.build_url(self.id) |
|
241 |
||
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
242 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
243 |
class UserInfoAction(Action): |
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:
554
diff
changeset
|
244 |
id = 'myinfos' |
707 | 245 |
__select__ = authenticated_user() |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
246 |
|
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:
554
diff
changeset
|
247 |
title = _('personnal informations') |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
248 |
category = 'useractions' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
249 |
order = 20 |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
250 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
251 |
def url(self): |
1545 | 252 |
return self.build_url('cwuser/%s'%self.req.user.login, vid='edition') |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
253 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
254 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
255 |
class LogoutAction(Action): |
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:
554
diff
changeset
|
256 |
id = 'logout' |
707 | 257 |
__select__ = authenticated_user() |
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
258 |
|
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:
554
diff
changeset
|
259 |
title = _('logout') |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
260 |
category = 'useractions' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
261 |
order = 30 |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
262 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
263 |
def url(self): |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
264 |
return self.build_url(self.id) |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
265 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
266 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
267 |
# site actions ################################################################ |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
268 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
269 |
class ManagersAction(Action): |
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:
554
diff
changeset
|
270 |
__abstract__ = True |
707 | 271 |
__select__ = match_user_groups('managers') |
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:
554
diff
changeset
|
272 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
273 |
category = 'siteactions' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
274 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
275 |
def url(self): |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
276 |
return self.build_url(self.id) |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
277 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
278 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
279 |
class SiteConfigurationAction(ManagersAction): |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
280 |
id = 'siteconfig' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
281 |
title = _('site configuration') |
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:
554
diff
changeset
|
282 |
order = 10 |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
283 |
|
1452
546b9884d92c
delete spaces, use .row .col instead of fixed 0 0
sylvain.thenault@logilab.fr
parents:
1398
diff
changeset
|
284 |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
285 |
class ManageAction(ManagersAction): |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
286 |
id = 'manage' |
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
287 |
title = _('manage') |
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:
554
diff
changeset
|
288 |
order = 20 |
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
289 |
|
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
290 |
|
870 | 291 |
from logilab.common.deprecation import class_moved |
292 |
from cubicweb.web.views.bookmark import FollowAction |
|
293 |
FollowAction = class_moved(FollowAction) |
|
401
bc55a104d636
cleanup, backport manage perm action from jpl
sylvain.thenault@logilab.fr
parents:
328
diff
changeset
|
294 |