author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 29 Sep 2011 15:28:41 +0200 | |
branch | stable |
changeset 7895 | 0a967180794b |
parent 7879 | 9aae456abab5 |
child 8190 | 2a3c1b787688 |
child 8254 | eff5b930998d |
permissions | -rw-r--r-- |
7432
cab99ccdb774
[ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7293
diff
changeset
|
1 |
# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
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:
5040
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
5886 | 18 |
"""abstract controller classe for CubicWeb web client""" |
0 | 19 |
|
20 |
__docformat__ = "restructuredtext en" |
|
21 |
||
4897
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
22 |
from logilab.mtconverter import xml_escape |
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
23 |
|
2819
b864288fd316
remove more 3.2 deprecated code, reintroduce checkbox used by formrenderers
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2792
diff
changeset
|
24 |
from cubicweb.selectors import yes |
722 | 25 |
from cubicweb.appobject import AppObject |
5694
ce2c108a9595
[pylint] fix detected name errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5556
diff
changeset
|
26 |
from cubicweb.mail import format_mail |
0 | 27 |
from cubicweb.web import LOGGER, Redirect, RequestError |
28 |
||
29 |
||
30 |
NAVIGATION_PARAMETERS = (('vid', '__redirectvid'), |
|
31 |
('rql', '__redirectrql'), |
|
32 |
('__redirectpath', '__redirectpath'), |
|
33 |
('__redirectparams', '__redirectparams'), |
|
34 |
) |
|
1103
f719caf263de
NAV_FORM_PARAMETERS should be a tuple
sylvain.thenault@logilab.fr
parents:
1092
diff
changeset
|
35 |
NAV_FORM_PARAMETERS = tuple(fp for ap, fp in NAVIGATION_PARAMETERS) |
0 | 36 |
|
37 |
def redirect_params(form): |
|
38 |
"""transform redirection parameters into navigation parameters |
|
39 |
""" |
|
40 |
params = {} |
|
41 |
# extract navigation parameters from redirection parameters |
|
42 |
for navparam, redirectparam in NAVIGATION_PARAMETERS: |
|
43 |
if navparam == redirectparam: |
|
44 |
continue |
|
45 |
if redirectparam in form: |
|
46 |
params[navparam] = form[redirectparam] |
|
47 |
return params |
|
48 |
||
49 |
def append_url_params(url, params): |
|
50 |
"""append raw parameters to the url. Given parameters, if any, are expected |
|
51 |
to be already url-quoted. |
|
52 |
""" |
|
53 |
if params: |
|
54 |
if not '?' in url: |
|
55 |
url += '?' |
|
56 |
else: |
|
57 |
url += '&' |
|
58 |
url += params |
|
59 |
return url |
|
60 |
||
61 |
||
62 |
class Controller(AppObject): |
|
63 |
"""a controller is responsible to make necessary stuff to publish |
|
64 |
a request. There is usually at least one standard "view" controller |
|
65 |
and another linked by forms to edit objects ("edit"). |
|
66 |
""" |
|
67 |
__registry__ = 'controllers' |
|
742
99115e029dca
replaced most of __selectors__ assignments with __select__
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
722
diff
changeset
|
68 |
__select__ = yes() |
0 | 69 |
|
70 |
def __init__(self, *args, **kwargs): |
|
2663
2bb628e0cc3b
[controller] should catch and set appli argument here now that the old AppObject class is gone
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2650
diff
changeset
|
71 |
self.appli = kwargs.pop('appli', None) |
0 | 72 |
super(Controller, self).__init__(*args, **kwargs) |
73 |
# attributes use to control after edition redirection |
|
74 |
self._after_deletion_path = None |
|
75 |
self._edited_entity = None |
|
1433 | 76 |
|
0 | 77 |
def publish(self, rset=None): |
4741
f9a176ebe090
[book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4719
diff
changeset
|
78 |
"""publish the current request, with an optional input rset""" |
0 | 79 |
raise NotImplementedError |
80 |
||
4741
f9a176ebe090
[book/controllers] add some content (overview, api super sketch) for the cubicweb controllers
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4719
diff
changeset
|
81 |
# generic methods useful for concrete implementations ###################### |
1092
b8fbb95dc0eb
process_rql now done in the controller
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
82 |
|
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
83 |
def process_rql(self): |
1092
b8fbb95dc0eb
process_rql now done in the controller
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
84 |
"""execute rql if specified""" |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
85 |
req = self._cw |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
86 |
rql = req.form.get('rql') |
1092
b8fbb95dc0eb
process_rql now done in the controller
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
87 |
if rql: |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
88 |
req.ensure_ro_rql(rql) |
1092
b8fbb95dc0eb
process_rql now done in the controller
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
89 |
if not isinstance(rql, unicode): |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
90 |
rql = unicode(rql, req.encoding) |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
91 |
pp = req.vreg['components'].select_or_none('magicsearch', req) |
2058
7ef12c03447c
nicer vreg api, try to make rset an optional named argument in select and derivated (including selectors)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2001
diff
changeset
|
92 |
if pp is not None: |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
93 |
return pp.process_query(rql) |
6542
f13c47ac9137
[ui controller] closes #1333236: configuring boxes crashes with traceback
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5890
diff
changeset
|
94 |
if 'eid' in req.form and not isinstance(req.form['eid'], list): |
5715
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
95 |
return req.eid_rset(req.form['eid']) |
2c3e83817a8e
[view] add a new entity_call method to entity view protocol, allowing some to work with not yet created entities. Also, start considering 'eid' form parameters where we only consider 'rql', so we can move on bloquing arbitrary rql inputs (more to do on this...)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5694
diff
changeset
|
96 |
return None |
1433 | 97 |
|
0 | 98 |
def notify_edited(self, entity): |
99 |
"""called by edit_entity() to notify which entity is edited""" |
|
100 |
# NOTE: we can't use entity.rest_path() at this point because |
|
101 |
# rest_path() could rely on schema constraints (such as a required |
|
102 |
# relation) that might not be satisfied yet (in case of creations) |
|
103 |
if not self._edited_entity: |
|
104 |
self._edited_entity = entity |
|
1433 | 105 |
|
4557
a0571ff0cb5d
[http cache/json controller] ensure json_view does proper cache validation #390986
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4212
diff
changeset
|
106 |
def validate_cache(self, view): |
a0571ff0cb5d
[http cache/json controller] ensure json_view does proper cache validation #390986
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
4212
diff
changeset
|
107 |
view.set_http_cache_headers() |
4666
737cbdb87e87
3.6 api update (introduced by merge)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4636
diff
changeset
|
108 |
self._cw.validate_cache() |
1433 | 109 |
|
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
110 |
def sendmail(self, recipient, subject, body): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
111 |
senderemail = self._cw.user.cw_adapt_to('IEmailable').get_email() |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
112 |
msg = format_mail({'email' : senderemail, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
113 |
'name' : self._cw.user.dc_title(),}, |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
114 |
[recipient], body, subject) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
115 |
if not self._cw.vreg.config.sendmails([(msg, [recipient])]): |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
116 |
msg = self._cw._('could not connect to the SMTP server') |
7879
9aae456abab5
[pylint] fix pylint detected errors and tweak it so that pylint -E will be much less verbose next time (+ update some copyrights on the way)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7432
diff
changeset
|
117 |
url = self._cw.build_url(__message=msg) |
5556
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
118 |
raise Redirect(url) |
9ab2b4c74baf
[entity] introduce a new 'adapters' registry
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
119 |
|
0 | 120 |
def reset(self): |
121 |
"""reset form parameters and redirect to a view determinated by given |
|
122 |
parameters |
|
123 |
""" |
|
124 |
newparams = {} |
|
125 |
# sets message if needed |
|
7432
cab99ccdb774
[ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7293
diff
changeset
|
126 |
# XXX - don't call .message twice since it pops the id |
cab99ccdb774
[ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7293
diff
changeset
|
127 |
msg = self._cw.message |
cab99ccdb774
[ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7293
diff
changeset
|
128 |
if msg: |
cab99ccdb774
[ui messages, xss] Start migration towards use of _msgid instead of __message (prone to XSS injection) closes #1698245
Arthur Lutz <arthur.lutz@logilab.fr>
parents:
7293
diff
changeset
|
129 |
newparams['_cwmsgid'] = self._cw.set_redirect_message(msg) |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
130 |
if self._cw.form.has_key('__action_apply'): |
0 | 131 |
self._return_to_edition_view(newparams) |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
132 |
if self._cw.form.has_key('__action_cancel'): |
0 | 133 |
self._return_to_lastpage(newparams) |
134 |
else: |
|
135 |
self._return_to_original_view(newparams) |
|
136 |
||
137 |
def _return_to_original_view(self, newparams): |
|
138 |
"""validate-button case""" |
|
139 |
# transforms __redirect[*] parameters into regular form parameters |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
140 |
newparams.update(redirect_params(self._cw.form)) |
0 | 141 |
# find out if we have some explicit `rql` needs |
142 |
rql = newparams.pop('rql', None) |
|
143 |
# if rql is needed (explicit __redirectrql or multiple deletions for |
|
144 |
# instance), we have to use the old `view?rql=...` form |
|
145 |
if rql: |
|
146 |
path = 'view' |
|
147 |
newparams['rql'] = rql |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
148 |
elif '__redirectpath' in self._cw.form: |
0 | 149 |
# if redirect path was explicitly specified in the form, use it |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
150 |
path = self._cw.form['__redirectpath'] |
4897
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
151 |
if (self._edited_entity and path != self._edited_entity.rest_path() |
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
152 |
and '_cwmsgid' in newparams): |
6866
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
153 |
# are we here on creation or modification? |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
154 |
if any(eid == self._edited_entity.eid |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
155 |
for eid in self._cw.data.get('eidmap', {}).values()): |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
156 |
msg = self._cw._('click here to see created entity') |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
157 |
else: |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
158 |
msg = self._cw._('click here to see edited entity') |
51d7868264b1
[after edition ui] closes #1381425: Wrong message : 'entity edited (click here to see created entity)'
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6542
diff
changeset
|
159 |
msg = u'(<a href="%s">%s</a>)' % (xml_escape(self._edited_entity.absolute_url()), msg) |
4897
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
160 |
self._cw.append_to_redirect_message(msg) |
0 | 161 |
elif self._after_deletion_path: |
162 |
# else it should have been set during form processing |
|
163 |
path, params = self._after_deletion_path |
|
164 |
params = dict(params) # params given as tuple |
|
165 |
params.update(newparams) |
|
166 |
newparams = params |
|
167 |
elif self._edited_entity: |
|
5040
00782905b720
[form controller] clear caches in case some attribute participating to the rest path has been modified, avoid redirection to a no more existant page (fix #753567)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4897
diff
changeset
|
168 |
# clear caches in case some attribute participating to the rest path |
00782905b720
[form controller] clear caches in case some attribute participating to the rest path has been modified, avoid redirection to a no more existant page (fix #753567)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4897
diff
changeset
|
169 |
# has been modified |
7293
97505b798975
[entity 3.13 api] rename clear_all_caches into cw_clear_all_cache
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6866
diff
changeset
|
170 |
self._edited_entity.cw_clear_all_caches() |
0 | 171 |
path = self._edited_entity.rest_path() |
172 |
else: |
|
173 |
path = 'view' |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2890
diff
changeset
|
174 |
url = self._cw.build_url(path, **newparams) |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
175 |
url = append_url_params(url, self._cw.form.get('__redirectparams')) |
0 | 176 |
raise Redirect(url) |
1433 | 177 |
|
0 | 178 |
def _return_to_edition_view(self, newparams): |
179 |
"""apply-button case""" |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
180 |
form = self._cw.form |
0 | 181 |
if self._edited_entity: |
182 |
path = self._edited_entity.rest_path() |
|
183 |
newparams.pop('rql', None) |
|
184 |
# else, fallback on the old `view?rql=...` url form |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
185 |
elif 'rql' in self._cw.form: |
0 | 186 |
path = 'view' |
187 |
newparams['rql'] = form['rql'] |
|
188 |
else: |
|
4897
e402e0b32075
[web] start a new message system based on id of message stored in session's data
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4884
diff
changeset
|
189 |
self.warning('the edited data seems inconsistent') |
0 | 190 |
path = 'view' |
191 |
# pick up the correction edition view |
|
192 |
if form.get('__form_id'): |
|
193 |
newparams['vid'] = form['__form_id'] |
|
194 |
# re-insert copy redirection parameters |
|
195 |
for redirectparam in NAV_FORM_PARAMETERS: |
|
196 |
if redirectparam in form: |
|
197 |
newparams[redirectparam] = form[redirectparam] |
|
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2890
diff
changeset
|
198 |
raise Redirect(self._cw.build_url(path, **newparams)) |
0 | 199 |
|
200 |
||
201 |
def _return_to_lastpage(self, newparams): |
|
202 |
"""cancel-button case: in this case we are always expecting to go back |
|
203 |
where we came from, and this is not easy. Currently we suppose that |
|
204 |
__redirectpath is specifying that place if found, else we look in the |
|
205 |
request breadcrumbs for the last visited page. |
|
206 |
""" |
|
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
207 |
if '__redirectpath' in self._cw.form: |
0 | 208 |
# if redirect path was explicitly specified in the form, use it |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
209 |
path = self._cw.form['__redirectpath'] |
3460
e4843535db25
[api] some more _cw / __regid__, automatic tests now pass again
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
2890
diff
changeset
|
210 |
url = self._cw.build_url(path, **newparams) |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
211 |
url = append_url_params(url, self._cw.form.get('__redirectparams')) |
0 | 212 |
else: |
3655
af86ab65a282
3.6 updates
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3460
diff
changeset
|
213 |
url = self._cw.last_visited_page() |
0 | 214 |
raise Redirect(url) |
215 |
||
216 |
||
217 |
from cubicweb import set_log_methods |
|
218 |
set_log_methods(Controller, LOGGER) |
|
219 |