@ -3,21 +3,18 @@
""" Views used by Pyramid when an exception is raised. """
""" Views used by Pyramid when an exception is raised. """
from pyramid.httpexceptions import HTTPNotFound
from pyramid.httpexceptions import HTTPException , HTTPForbidden , HTTP NotFound
from pyramid.request import Request
from pyramid.request import Request
from pyramid.view import forbidden_view_config , exception_view_config
from pyramid.view import (
exception_view_config ,
forbidden_view_config ,
notfound_view_config ,
)
from sqlalchemy import cast , desc , func , Text
from sqlalchemy import cast , desc , func , Text
from tildes.models.group import Group
from tildes.models.group import Group
@forbidden_view_config ( xhr = False , renderer = " error_403.jinja2 " )
def forbidden ( request : Request ) - > dict :
""" 403 Forbidden page. """
request . response . status_int = 403
return { }
@exception_view_config (
@exception_view_config (
HTTPNotFound , route_name = " group " , renderer = " error_group_not_found.jinja2 "
HTTPNotFound , route_name = " group " , renderer = " error_group_not_found.jinja2 "
)
)
@ -34,3 +31,20 @@ def group_not_found(request: Request) -> dict:
. all ( )
. all ( )
)
)
return { " group_suggestions " : group_suggestions , " supplied_name " : supplied_name }
return { " group_suggestions " : group_suggestions , " supplied_name " : supplied_name }
@notfound_view_config ( xhr = False , renderer = " error_page.jinja2 " )
@forbidden_view_config ( xhr = False , renderer = " error_page.jinja2 " )
@exception_view_config ( context = HTTPException , xhr = False , renderer = " error_page.jinja2 " )
def generic_error_page ( request : Request ) - > dict :
""" Display a generic error page for all HTTP exceptions. """
request . response . status_int = request . exception . status_int
error = f " Error {request.exception.status_code} ({request.exception.title}) "
if isinstance ( request . exception , HTTPForbidden ) :
description = " You don ' t have access to this page "
else :
description = request . exception . explanation
return { " error " : error , " description " : description }