author | Nicolas Chauvat <nicolas.chauvat@logilab.fr> |
Thu, 23 Jul 2009 15:15:58 +0200 | |
changeset 2449 | 888d698af3f9 |
parent 2293 | 7ded2a1416e4 |
child 2476 | 1294a6bdf3bf |
permissions | -rw-r--r-- |
0 | 1 |
"""CubicWeb web client application object |
2 |
||
3 |
:organization: Logilab |
|
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1426
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:
1426
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
0 | 7 |
""" |
8 |
__docformat__ = "restructuredtext en" |
|
9 |
||
10 |
import sys |
|
11 |
from time import clock, time |
|
12 |
||
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:
1977
diff
changeset
|
13 |
from logilab.common.deprecation import obsolete |
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:
1977
diff
changeset
|
14 |
|
0 | 15 |
from rql import BadRQLQuery |
16 |
||
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:
1977
diff
changeset
|
17 |
from cubicweb import set_log_methods, cwvreg |
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:
1977
diff
changeset
|
18 |
from cubicweb import ( |
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:
1977
diff
changeset
|
19 |
ValidationError, Unauthorized, AuthenticationError, NoSelectableObject, |
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:
1977
diff
changeset
|
20 |
RepositoryError) |
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:
1977
diff
changeset
|
21 |
from cubicweb.web import LOGGER, component |
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:
1977
diff
changeset
|
22 |
from cubicweb.web import ( |
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:
1977
diff
changeset
|
23 |
StatusResponse, DirectResponse, Redirect, NotFound, |
2293 | 24 |
RemoteCallFailed, ExplicitLogin, InvalidSession, RequestError) |
0 | 25 |
|
26 |
# make session manager available through a global variable so the debug view can |
|
27 |
# print information about web session |
|
28 |
SESSION_MANAGER = None |
|
29 |
||
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:
1977
diff
changeset
|
30 |
class AbstractSessionManager(component.Component): |
0 | 31 |
"""manage session data associated to a session identifier""" |
32 |
id = 'sessionmanager' |
|
1426 | 33 |
|
0 | 34 |
def __init__(self): |
35 |
self.session_time = self.vreg.config['http-session-time'] or None |
|
36 |
assert self.session_time is None or self.session_time > 0 |
|
168
f6be0c92fc38
fix default values
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
37 |
self.cleanup_session_time = self.vreg.config['cleanup-session-time'] or 43200 |
0 | 38 |
assert self.cleanup_session_time > 0 |
168
f6be0c92fc38
fix default values
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
0
diff
changeset
|
39 |
self.cleanup_anon_session_time = self.vreg.config['cleanup-anonymous-session-time'] or 120 |
0 | 40 |
assert self.cleanup_anon_session_time > 0 |
41 |
if self.session_time: |
|
42 |
assert self.cleanup_session_time < self.session_time |
|
43 |
assert self.cleanup_anon_session_time < self.session_time |
|
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:
1977
diff
changeset
|
44 |
self.authmanager = self.vreg.select('components', 'authmanager') |
1426 | 45 |
|
0 | 46 |
def clean_sessions(self): |
47 |
"""cleanup sessions which has not been unused since a given amount of |
|
48 |
time. Return the number of sessions which have been closed. |
|
49 |
""" |
|
50 |
self.debug('cleaning http sessions') |
|
51 |
closed, total = 0, 0 |
|
52 |
for session in self.current_sessions(): |
|
53 |
no_use_time = (time() - session.last_usage_time) |
|
54 |
total += 1 |
|
55 |
if session.anonymous_connection: |
|
56 |
if no_use_time >= self.cleanup_anon_session_time: |
|
57 |
self.close_session(session) |
|
58 |
closed += 1 |
|
59 |
elif no_use_time >= self.cleanup_session_time: |
|
60 |
self.close_session(session) |
|
61 |
closed += 1 |
|
62 |
return closed, total - closed |
|
1426 | 63 |
|
0 | 64 |
def has_expired(self, session): |
65 |
"""return True if the web session associated to the session is expired |
|
66 |
""" |
|
67 |
return not (self.session_time is None or |
|
68 |
time() < session.last_usage_time + self.session_time) |
|
1426 | 69 |
|
0 | 70 |
def current_sessions(self): |
71 |
"""return currently open sessions""" |
|
72 |
raise NotImplementedError() |
|
1426 | 73 |
|
0 | 74 |
def get_session(self, req, sessionid): |
75 |
"""return existing session for the given session identifier""" |
|
76 |
raise NotImplementedError() |
|
77 |
||
78 |
def open_session(self, req): |
|
79 |
"""open and return a new session for the given request |
|
1426 | 80 |
|
0 | 81 |
:raise ExplicitLogin: if authentication is required |
82 |
""" |
|
83 |
raise NotImplementedError() |
|
1426 | 84 |
|
0 | 85 |
def close_session(self, session): |
86 |
"""close session on logout or on invalid session detected (expired out, |
|
87 |
corrupted...) |
|
88 |
""" |
|
89 |
raise NotImplementedError() |
|
90 |
||
91 |
||
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:
1977
diff
changeset
|
92 |
class AbstractAuthenticationManager(component.Component): |
0 | 93 |
"""authenticate user associated to a request and check session validity""" |
94 |
id = 'authmanager' |
|
95 |
||
96 |
def authenticate(self, req): |
|
97 |
"""authenticate user and return corresponding user object |
|
1426 | 98 |
|
0 | 99 |
:raise ExplicitLogin: if authentication is required (no authentication |
100 |
info found or wrong user/password) |
|
101 |
""" |
|
102 |
raise NotImplementedError() |
|
103 |
||
1426 | 104 |
|
0 | 105 |
class CookieSessionHandler(object): |
106 |
"""a session handler using a cookie to store the session identifier |
|
107 |
||
108 |
:cvar SESSION_VAR: |
|
109 |
string giving the name of the variable used to store the session |
|
110 |
identifier |
|
111 |
""" |
|
112 |
SESSION_VAR = '__session' |
|
1426 | 113 |
|
0 | 114 |
def __init__(self, appli): |
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:
1977
diff
changeset
|
115 |
self.session_manager = appli.vreg.select('components', 'sessionmanager') |
0 | 116 |
global SESSION_MANAGER |
117 |
SESSION_MANAGER = self.session_manager |
|
118 |
if not 'last_login_time' in appli.vreg.schema: |
|
119 |
self._update_last_login_time = lambda x: None |
|
120 |
||
121 |
def clean_sessions(self): |
|
122 |
"""cleanup sessions which has not been unused since a given amount of |
|
123 |
time |
|
124 |
""" |
|
125 |
self.session_manager.clean_sessions() |
|
1426 | 126 |
|
0 | 127 |
def set_session(self, req): |
128 |
"""associate a session to the request |
|
129 |
||
130 |
Session id is searched from : |
|
131 |
- # form variable |
|
132 |
- cookie |
|
133 |
||
134 |
if no session id is found, open a new session for the connected user |
|
135 |
or request authentification as needed |
|
136 |
||
1426 | 137 |
:raise Redirect: if authentication has occured and succeed |
0 | 138 |
""" |
139 |
assert req.cnx is None # at this point no cnx should be set on the request |
|
140 |
cookie = req.get_cookie() |
|
141 |
try: |
|
142 |
sessionid = str(cookie[self.SESSION_VAR].value) |
|
143 |
except KeyError: # no session cookie |
|
144 |
session = self.open_session(req) |
|
145 |
else: |
|
146 |
try: |
|
147 |
session = self.get_session(req, sessionid) |
|
148 |
except InvalidSession: |
|
149 |
try: |
|
150 |
session = self.open_session(req) |
|
151 |
except ExplicitLogin: |
|
152 |
req.remove_cookie(cookie, self.SESSION_VAR) |
|
153 |
raise |
|
154 |
# remember last usage time for web session tracking |
|
155 |
session.last_usage_time = time() |
|
156 |
||
157 |
def get_session(self, req, sessionid): |
|
158 |
return self.session_manager.get_session(req, sessionid) |
|
1426 | 159 |
|
0 | 160 |
def open_session(self, req): |
161 |
session = self.session_manager.open_session(req) |
|
162 |
cookie = req.get_cookie() |
|
163 |
cookie[self.SESSION_VAR] = session.sessionid |
|
164 |
req.set_cookie(cookie, self.SESSION_VAR, maxage=None) |
|
165 |
# remember last usage time for web session tracking |
|
166 |
session.last_usage_time = time() |
|
167 |
if not session.anonymous_connection: |
|
168 |
self._postlogin(req) |
|
169 |
return session |
|
170 |
||
171 |
def _update_last_login_time(self, req): |
|
172 |
try: |
|
173 |
req.execute('SET X last_login_time NOW WHERE X eid %(x)s', |
|
174 |
{'x' : req.user.eid}, 'x') |
|
175 |
req.cnx.commit() |
|
176 |
except (RepositoryError, Unauthorized): |
|
177 |
# ldap user are not writeable for instance |
|
178 |
req.cnx.rollback() |
|
179 |
except: |
|
180 |
req.cnx.rollback() |
|
181 |
raise |
|
1426 | 182 |
|
0 | 183 |
def _postlogin(self, req): |
184 |
"""postlogin: the user has been authenticated, redirect to the original |
|
185 |
page (index by default) with a welcome message |
|
186 |
""" |
|
187 |
# Update last connection date |
|
188 |
# XXX: this should be in a post login hook in the repository, but there |
|
189 |
# we can't differentiate actual login of automatic session |
|
190 |
# reopening. Is it actually a problem? |
|
191 |
self._update_last_login_time(req) |
|
192 |
args = req.form |
|
193 |
args['__message'] = req._('welcome %s !') % req.user.login |
|
194 |
if 'vid' in req.form: |
|
195 |
args['vid'] = req.form['vid'] |
|
196 |
if 'rql' in req.form: |
|
197 |
args['rql'] = req.form['rql'] |
|
198 |
path = req.relative_path(False) |
|
199 |
if path == 'login': |
|
200 |
path = 'view' |
|
201 |
raise Redirect(req.build_url(path, **args)) |
|
1426 | 202 |
|
0 | 203 |
def logout(self, req): |
204 |
"""logout from the application by cleaning the session and raising |
|
205 |
`AuthenticationError` |
|
206 |
""" |
|
207 |
self.session_manager.close_session(req.cnx) |
|
208 |
req.remove_cookie(req.get_cookie(), self.SESSION_VAR) |
|
209 |
raise AuthenticationError() |
|
210 |
||
211 |
||
212 |
class CubicWebPublisher(object): |
|
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:
1977
diff
changeset
|
213 |
"""the publisher is a singleton hold by the web frontend, and is responsible |
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:
1977
diff
changeset
|
214 |
to publish HTTP request. |
0 | 215 |
""" |
1426 | 216 |
|
0 | 217 |
def __init__(self, config, debug=None, |
218 |
session_handler_fact=CookieSessionHandler, |
|
219 |
vreg=None): |
|
220 |
super(CubicWebPublisher, self).__init__() |
|
221 |
# connect to the repository and get application's schema |
|
222 |
if vreg is None: |
|
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:
1977
diff
changeset
|
223 |
vreg = cwvreg.CubicWebRegistry(config, debug=debug) |
0 | 224 |
self.vreg = vreg |
225 |
self.info('starting web application from %s', config.apphome) |
|
226 |
self.repo = config.repository(vreg) |
|
227 |
if not vreg.initialized: |
|
228 |
self.config.init_cubes(self.repo.get_cubes()) |
|
229 |
vreg.init_properties(self.repo.properties()) |
|
230 |
vreg.set_schema(self.repo.get_schema()) |
|
231 |
# set the correct publish method |
|
232 |
if config['query-log-file']: |
|
233 |
from threading import Lock |
|
234 |
self._query_log = open(config['query-log-file'], 'a') |
|
235 |
self.publish = self.log_publish |
|
1426 | 236 |
self._logfile_lock = Lock() |
0 | 237 |
else: |
238 |
self._query_log = None |
|
239 |
self.publish = self.main_publish |
|
240 |
# instantiate session and url resolving helpers |
|
241 |
self.session_handler = session_handler_fact(self) |
|
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:
1977
diff
changeset
|
242 |
self.url_resolver = vreg.select('components', 'urlpublisher') |
1426 | 243 |
|
0 | 244 |
def connect(self, req): |
245 |
"""return a connection for a logged user object according to existing |
|
246 |
sessions (i.e. a new connection may be created or an already existing |
|
247 |
one may be reused |
|
248 |
""" |
|
249 |
self.session_handler.set_session(req) |
|
250 |
||
251 |
# publish methods ######################################################### |
|
1426 | 252 |
|
0 | 253 |
def log_publish(self, path, req): |
254 |
"""wrapper around _publish to log all queries executed for a given |
|
255 |
accessed path |
|
256 |
""" |
|
257 |
try: |
|
258 |
return self.main_publish(path, req) |
|
259 |
finally: |
|
260 |
cnx = req.cnx |
|
261 |
self._logfile_lock.acquire() |
|
262 |
try: |
|
263 |
try: |
|
264 |
result = ['\n'+'*'*80] |
|
265 |
result.append(req.url()) |
|
266 |
result += ['%s %s -- (%.3f sec, %.3f CPU sec)' % q for q in cnx.executed_queries] |
|
267 |
cnx.executed_queries = [] |
|
268 |
self._query_log.write('\n'.join(result).encode(req.encoding)) |
|
269 |
self._query_log.flush() |
|
270 |
except Exception: |
|
271 |
self.exception('error while logging queries') |
|
272 |
finally: |
|
273 |
self._logfile_lock.release() |
|
274 |
||
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:
1977
diff
changeset
|
275 |
@obsolete("use vreg.select('controllers', ...)") |
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:
1977
diff
changeset
|
276 |
def select_controller(self, oid, req): |
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:
1977
diff
changeset
|
277 |
try: |
2235 | 278 |
return self.vreg.select('controllers', oid, req=req, appli=self) |
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:
1977
diff
changeset
|
279 |
except NoSelectableObject: |
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:
1977
diff
changeset
|
280 |
raise Unauthorized(req._('not authorized')) |
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:
1977
diff
changeset
|
281 |
|
0 | 282 |
def main_publish(self, path, req): |
283 |
"""method called by the main publisher to process <path> |
|
1426 | 284 |
|
0 | 285 |
should return a string containing the resulting page or raise a |
286 |
`NotFound` exception |
|
287 |
||
288 |
:type path: str |
|
289 |
:param path: the path part of the url to publish |
|
1426 | 290 |
|
0 | 291 |
:type req: `web.Request` |
292 |
:param req: the request object |
|
293 |
||
294 |
:rtype: str |
|
295 |
:return: the result of the pusblished url |
|
296 |
""" |
|
297 |
path = path or 'view' |
|
298 |
# don't log form values they may contains sensitive information |
|
299 |
self.info('publish "%s" (form params: %s)', path, req.form.keys()) |
|
300 |
# remove user callbacks on a new request (except for json controllers |
|
301 |
# to avoid callbacks being unregistered before they could be called) |
|
302 |
tstart = clock() |
|
303 |
try: |
|
304 |
try: |
|
305 |
ctrlid, rset = self.url_resolver.process(req, path) |
|
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:
1977
diff
changeset
|
306 |
try: |
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:
1977
diff
changeset
|
307 |
controller = self.vreg.select('controllers', ctrlid, req, |
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:
1977
diff
changeset
|
308 |
appli=self) |
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:
1977
diff
changeset
|
309 |
except NoSelectableObject: |
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:
1977
diff
changeset
|
310 |
raise Unauthorized(req._('not authorized')) |
581
09f87f2c535e
update_search_state in the publisher since it should be done whatever the controller
sylvain.thenault@logilab.fr
parents:
168
diff
changeset
|
311 |
req.update_search_state() |
0 | 312 |
result = controller.publish(rset=rset) |
313 |
if req.cnx is not None: |
|
314 |
# req.cnx is None if anonymous aren't allowed and we are |
|
315 |
# displaying the cookie authentication form |
|
316 |
req.cnx.commit() |
|
317 |
except (StatusResponse, DirectResponse): |
|
318 |
req.cnx.commit() |
|
319 |
raise |
|
320 |
except Redirect: |
|
321 |
# redirect is raised by edit controller when everything went fine, |
|
322 |
# so try to commit |
|
323 |
try: |
|
324 |
req.cnx.commit() |
|
325 |
except ValidationError, ex: |
|
326 |
self.validation_error_handler(req, ex) |
|
327 |
except Unauthorized, ex: |
|
328 |
req.data['errmsg'] = req._('You\'re not authorized to access this page. ' |
|
329 |
'If you think you should, please contact the site administrator.') |
|
330 |
self.error_handler(req, ex, tb=False) |
|
331 |
except Exception, ex: |
|
332 |
self.error_handler(req, ex, tb=True) |
|
333 |
else: |
|
334 |
# delete validation errors which may have been previously set |
|
335 |
if '__errorurl' in req.form: |
|
336 |
req.del_session_data(req.form['__errorurl']) |
|
337 |
raise |
|
338 |
except (AuthenticationError, NotFound, RemoteCallFailed): |
|
339 |
raise |
|
340 |
except ValidationError, ex: |
|
341 |
self.validation_error_handler(req, ex) |
|
2272
f27a3a75be0d
no tb for RequestError
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2263
diff
changeset
|
342 |
except (Unauthorized, BadRQLQuery, RequestError), ex: |
0 | 343 |
self.error_handler(req, ex, tb=False) |
344 |
except Exception, ex: |
|
345 |
self.error_handler(req, ex, tb=True) |
|
346 |
finally: |
|
347 |
if req.cnx is not None: |
|
348 |
try: |
|
349 |
req.cnx.rollback() |
|
350 |
except: |
|
351 |
pass # ignore rollback error at this point |
|
352 |
self.info('query %s executed in %s sec', req.relative_path(), clock() - tstart) |
|
353 |
return result |
|
354 |
||
355 |
def validation_error_handler(self, req, ex): |
|
356 |
ex.errors = dict((k, v) for k, v in ex.errors.items()) |
|
357 |
if '__errorurl' in req.form: |
|
358 |
forminfo = {'errors': ex, |
|
359 |
'values': req.form, |
|
360 |
'eidmap': req.data.get('eidmap', {}) |
|
361 |
} |
|
362 |
req.set_session_data(req.form['__errorurl'], forminfo) |
|
363 |
raise Redirect(req.form['__errorurl']) |
|
364 |
self.error_handler(req, ex, tb=False) |
|
1426 | 365 |
|
0 | 366 |
def error_handler(self, req, ex, tb=False): |
367 |
excinfo = sys.exc_info() |
|
368 |
self.exception(repr(ex)) |
|
369 |
req.set_header('Cache-Control', 'no-cache') |
|
370 |
req.remove_header('Etag') |
|
371 |
req.message = None |
|
372 |
req.reset_headers() |
|
373 |
try: |
|
374 |
req.data['ex'] = ex |
|
375 |
if tb: |
|
376 |
req.data['excinfo'] = excinfo |
|
377 |
req.form['vid'] = 'error' |
|
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:
1977
diff
changeset
|
378 |
errview = self.vreg.select('views', 'error', req) |
882
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
379 |
template = self.main_template_id(req) |
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
380 |
content = self.vreg.main_template(req, template, view=errview) |
0 | 381 |
except: |
832
8e06873d80d3
rename error template to avoid conflicts with the error view
sylvain.thenault@logilab.fr
parents:
823
diff
changeset
|
382 |
content = self.vreg.main_template(req, 'error-template') |
0 | 383 |
raise StatusResponse(500, content) |
1426 | 384 |
|
0 | 385 |
def need_login_content(self, req): |
386 |
return self.vreg.main_template(req, 'login') |
|
1426 | 387 |
|
0 | 388 |
def loggedout_content(self, req): |
389 |
return self.vreg.main_template(req, 'loggedout') |
|
1426 | 390 |
|
0 | 391 |
def notfound_content(self, req): |
392 |
req.form['vid'] = '404' |
|
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:
1977
diff
changeset
|
393 |
view = self.vreg.select('views', '404', req) |
882
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
394 |
template = self.main_template_id(req) |
823
cb8ccbef8fa5
main template refactoring
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
661
diff
changeset
|
395 |
return self.vreg.main_template(req, template, view=view) |
0 | 396 |
|
882
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
397 |
def main_template_id(self, req): |
2263
1f59cd5b710f
accept a __template parameter that specifies a different (main) template
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
398 |
template = req.form.get('__template', req.property_value('ui.main-template')) |
1f59cd5b710f
accept a __template parameter that specifies a different (main) template
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
1977
diff
changeset
|
399 |
if template not in self.vreg.registry('views'): |
882
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
400 |
template = 'main-template' |
75488a2a875e
fix ui.main-template property handling
sylvain.thenault@logilab.fr
parents:
871
diff
changeset
|
401 |
return template |
1426 | 402 |
|
0 | 403 |
|
404 |
set_log_methods(CubicWebPublisher, LOGGER) |
|
405 |
set_log_methods(CookieSessionHandler, LOGGER) |