web/application.py
changeset 8695 358d8bed9626
parent 8694 d901c36bcfce
child 8696 0bb18407c053
equal deleted inserted replaced
8694:d901c36bcfce 8695:358d8bed9626
   360             # handler
   360             # handler
   361             try:
   361             try:
   362                 ### Try to generate the actual request content
   362                 ### Try to generate the actual request content
   363                 content = self.core_handle(req, path)
   363                 content = self.core_handle(req, path)
   364             # Handle user log-out
   364             # Handle user log-out
   365             except LogOut, ex:
   365             except LogOut as ex:
   366                 # When authentification is handled by cookie the code that
   366                 # When authentification is handled by cookie the code that
   367                 # raised LogOut must has invalidated the cookie. We can just
   367                 # raised LogOut must has invalidated the cookie. We can just
   368                 # reload the original url without authentification
   368                 # reload the original url without authentification
   369                 if self.vreg.config['auth-mode'] == 'cookie' and ex.url:
   369                 if self.vreg.config['auth-mode'] == 'cookie' and ex.url:
   370                     req.headers_out.setHeader('location', str(ex.url))
   370                     req.headers_out.setHeader('location', str(ex.url))
   378                     # assignement to ``content`` prevent standard
   378                     # assignement to ``content`` prevent standard
   379                     # AuthenticationError code to overwrite it.
   379                     # AuthenticationError code to overwrite it.
   380                     content = self.loggedout_content(req)
   380                     content = self.loggedout_content(req)
   381                     # let the explicitly reset http credential
   381                     # let the explicitly reset http credential
   382                     raise AuthenticationError()
   382                     raise AuthenticationError()
   383         except Redirect, ex:
   383         except Redirect as ex:
   384             # authentication needs redirection (eg openid)
   384             # authentication needs redirection (eg openid)
   385             content = self.redirect_handler(req, ex)
   385             content = self.redirect_handler(req, ex)
   386         # Wrong, absent or Reseted credential
   386         # Wrong, absent or Reseted credential
   387         except AuthenticationError:
   387         except AuthenticationError:
   388             # If there is an https url configured and
   388             # If there is an https url configured and
   439                                                                  appli=self)
   439                                                                  appli=self)
   440                 except NoSelectableObject:
   440                 except NoSelectableObject:
   441                     raise Unauthorized(req._('not authorized'))
   441                     raise Unauthorized(req._('not authorized'))
   442                 req.update_search_state()
   442                 req.update_search_state()
   443                 result = controller.publish(rset=rset)
   443                 result = controller.publish(rset=rset)
   444             except StatusResponse, ex:
   444             except StatusResponse as ex:
   445                 warn('StatusResponse is deprecated use req.status_out',
   445                 warn('StatusResponse is deprecated use req.status_out',
   446                      DeprecationWarning)
   446                      DeprecationWarning)
   447                 result = ex.content
   447                 result = ex.content
   448                 req.status_out = ex.status
   448                 req.status_out = ex.status
   449             except Redirect, ex:
   449             except Redirect as ex:
   450                 # Redirect may be raised by edit controller when everything went
   450                 # Redirect may be raised by edit controller when everything went
   451                 # fine, so attempt to commit
   451                 # fine, so attempt to commit
   452                 result = self.redirect_handler(req, ex)
   452                 result = self.redirect_handler(req, ex)
   453             if req.cnx:
   453             if req.cnx:
   454                 txuuid = req.cnx.commit()
   454                 txuuid = req.cnx.commit()
   455                 commited = True
   455                 commited = True
   456                 if txuuid is not None:
   456                 if txuuid is not None:
   457                     req.data['last_undoable_transaction'] = txuuid
   457                     req.data['last_undoable_transaction'] = txuuid
   458         ### error case
   458         ### error case
   459         except NotFound, ex:
   459         except NotFound as ex:
   460             result = self.notfound_content(req)
   460             result = self.notfound_content(req)
   461             req.status_out = ex.status
   461             req.status_out = ex.status
   462         except ValidationError, ex:
   462         except ValidationError as ex:
   463             result = self.validation_error_handler(req, ex)
   463             result = self.validation_error_handler(req, ex)
   464         except RemoteCallFailed, ex:
   464         except RemoteCallFailed as ex:
   465             result = self.ajax_error_handler(req, ex)
   465             result = self.ajax_error_handler(req, ex)
   466         except Unauthorized, ex:
   466         except Unauthorized as ex:
   467             req.data['errmsg'] = req._('You\'re not authorized to access this page. '
   467             req.data['errmsg'] = req._('You\'re not authorized to access this page. '
   468                                        'If you think you should, please contact the site administrator.')
   468                                        'If you think you should, please contact the site administrator.')
   469             req.status_out = httplib.UNAUTHORIZED
   469             req.status_out = httplib.UNAUTHORIZED
   470             result = self.error_handler(req, ex, tb=False)
   470             result = self.error_handler(req, ex, tb=False)
   471         except Forbidden, ex:
   471         except Forbidden as ex:
   472             req.data['errmsg'] = req._('This action is forbidden. '
   472             req.data['errmsg'] = req._('This action is forbidden. '
   473                                        'If you think it should be allowed, please contact the site administrator.')
   473                                        'If you think it should be allowed, please contact the site administrator.')
   474             req.status_out = httplib.FORBIDDEN
   474             req.status_out = httplib.FORBIDDEN
   475             result = self.error_handler(req, ex, tb=False)
   475             result = self.error_handler(req, ex, tb=False)
   476         except (BadRQLQuery, RequestError), ex:
   476         except (BadRQLQuery, RequestError) as ex:
   477             result = self.error_handler(req, ex, tb=False)
   477             result = self.error_handler(req, ex, tb=False)
   478         ### pass through exception
   478         ### pass through exception
   479         except DirectResponse:
   479         except DirectResponse:
   480             if req.cnx:
   480             if req.cnx:
   481                 req.cnx.commit()
   481                 req.cnx.commit()
   482             raise
   482             raise
   483         except (AuthenticationError, LogOut):
   483         except (AuthenticationError, LogOut):
   484             # the rollback is handled in the finally
   484             # the rollback is handled in the finally
   485             raise
   485             raise
   486         ### Last defense line
   486         ### Last defense line
   487         except BaseException, ex:
   487         except BaseException as ex:
   488             result = self.error_handler(req, ex, tb=True)
   488             result = self.error_handler(req, ex, tb=True)
   489         finally:
   489         finally:
   490             if req.cnx and not commited:
   490             if req.cnx and not commited:
   491                 try:
   491                 try:
   492                     req.cnx.rollback()
   492                     req.cnx.rollback()