379 # assignement to ``content`` prevent standard |
379 # assignement to ``content`` prevent standard |
380 # AuthenticationError code to overwrite it. |
380 # AuthenticationError code to overwrite it. |
381 content = self.loggedout_content(req) |
381 content = self.loggedout_content(req) |
382 # let the explicitly reset http credential |
382 # let the explicitly reset http credential |
383 raise AuthenticationError() |
383 raise AuthenticationError() |
|
384 except Redirect, ex: |
|
385 # authentication needs redirection (eg openid) |
|
386 content = self.redirect_handler(req, ex) |
384 # Wrong, absent or Reseted credential |
387 # Wrong, absent or Reseted credential |
385 except AuthenticationError: |
388 except AuthenticationError: |
386 # If there is an https url configured and |
389 # If there is an https url configured and |
387 # the request do not used https, redirect to login form |
390 # the request do not used https, redirect to login form |
388 https_url = self.vreg.config['https-url'] |
391 https_url = self.vreg.config['https-url'] |
443 warn('StatusResponse is deprecated use req.status_out', |
446 warn('StatusResponse is deprecated use req.status_out', |
444 DeprecationWarning) |
447 DeprecationWarning) |
445 result = ex.content |
448 result = ex.content |
446 req.status_out = ex.status |
449 req.status_out = ex.status |
447 except Redirect, ex: |
450 except Redirect, ex: |
448 # handle redirect |
451 # Redirect may be raised by edit controller when everything went |
449 # - comply to ex status |
452 # fine, so attempt to commit |
450 # - set header field |
453 result = self.redirect_handler(req, ex) |
451 # |
|
452 # Redirect Maybe be is raised by edit controller when |
|
453 # everything went fine, so try to commit |
|
454 self.debug('redirecting to %s', str(ex.location)) |
|
455 req.headers_out.setHeader('location', str(ex.location)) |
|
456 assert 300<= ex.status < 400 |
|
457 req.status_out = ex.status |
|
458 result = '' |
|
459 if req.cnx: |
454 if req.cnx: |
460 txuuid = req.cnx.commit() |
455 txuuid = req.cnx.commit() |
461 commited = True |
456 commited = True |
462 if txuuid is not None: |
457 if txuuid is not None: |
463 req.data['last_undoable_transaction'] = txuuid |
458 req.data['last_undoable_transaction'] = txuuid |
499 req.drop_entity_cache() |
494 req.drop_entity_cache() |
500 self.add_undo_link_to_msg(req) |
495 self.add_undo_link_to_msg(req) |
501 self.debug('query %s executed in %s sec', req.relative_path(), clock() - tstart) |
496 self.debug('query %s executed in %s sec', req.relative_path(), clock() - tstart) |
502 return result |
497 return result |
503 |
498 |
504 ### Error handler |
499 # Error handlers |
|
500 |
|
501 def redirect_handler(self, req, ex): |
|
502 """handle redirect |
|
503 - comply to ex status |
|
504 - set header field |
|
505 - return empty content |
|
506 """ |
|
507 self.debug('redirecting to %s', str(ex.location)) |
|
508 req.headers_out.setHeader('location', str(ex.location)) |
|
509 assert 300 <= ex.status < 400 |
|
510 req.status_out = ex.status |
|
511 return '' |
|
512 |
505 def validation_error_handler(self, req, ex): |
513 def validation_error_handler(self, req, ex): |
506 ex.errors = dict((k, v) for k, v in ex.errors.items()) |
514 ex.errors = dict((k, v) for k, v in ex.errors.items()) |
507 if '__errorurl' in req.form: |
515 if '__errorurl' in req.form: |
508 forminfo = {'error': ex, |
516 forminfo = {'error': ex, |
509 'values': req.form, |
517 'values': req.form, |
549 if txuuid is not None: |
557 if txuuid is not None: |
550 msg = u'<span class="undo">[<a href="%s">%s</a>]</span>' %( |
558 msg = u'<span class="undo">[<a href="%s">%s</a>]</span>' %( |
551 req.build_url('undo', txuuid=txuuid), req._('undo')) |
559 req.build_url('undo', txuuid=txuuid), req._('undo')) |
552 req.append_to_redirect_message(msg) |
560 req.append_to_redirect_message(msg) |
553 |
561 |
554 |
|
555 |
|
556 def ajax_error_handler(self, req, ex): |
562 def ajax_error_handler(self, req, ex): |
557 req.set_header('content-type', 'application/json') |
563 req.set_header('content-type', 'application/json') |
558 status = ex.status |
564 status = ex.status |
559 if status is None: |
565 if status is None: |
560 status = httplib.INTERNAL_SERVER_ERROR |
566 status = httplib.INTERNAL_SERVER_ERROR |