This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/passbook/core/views/error.py

68 lines
1.8 KiB
Python
Raw Normal View History

2019-03-22 11:16:30 +00:00
"""passbook core error views"""
2019-12-31 11:51:16 +00:00
from django.http.response import (
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseServerError,
)
2019-03-22 11:16:30 +00:00
from django.template.response import TemplateResponse
from django.views.generic import TemplateView
class BadRequestTemplateResponse(TemplateResponse, HttpResponseBadRequest):
"""Combine Template response with Http Code 400"""
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class ForbiddenTemplateResponse(TemplateResponse, HttpResponseForbidden):
"""Combine Template response with Http Code 403"""
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class NotFoundTemplateResponse(TemplateResponse, HttpResponseNotFound):
"""Combine Template response with Http Code 404"""
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class ServerErrorTemplateResponse(TemplateResponse, HttpResponseServerError):
"""Combine Template response with Http Code 500"""
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class BadRequestView(TemplateView):
"""Show Bad Request message"""
2020-11-24 21:46:50 +00:00
extra_context = {"title": "Bad Request"}
2019-03-22 11:16:30 +00:00
response_class = BadRequestTemplateResponse
template_name = "error/generic.html"
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class ForbiddenView(TemplateView):
"""Show Forbidden message"""
2020-11-24 21:46:50 +00:00
extra_context = {"title": "Forbidden"}
2019-03-22 11:16:30 +00:00
response_class = ForbiddenTemplateResponse
template_name = "error/generic.html"
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class NotFoundView(TemplateView):
"""Show Not Found message"""
2020-11-24 21:46:50 +00:00
extra_context = {"title": "Not Found"}
2019-03-22 11:16:30 +00:00
response_class = NotFoundTemplateResponse
template_name = "error/generic.html"
2019-12-31 11:51:16 +00:00
2019-03-22 11:16:30 +00:00
class ServerErrorView(TemplateView):
"""Show Server Error message"""
2020-11-24 21:46:50 +00:00
extra_context = {"title": "Server Error"}
2019-03-22 11:16:30 +00:00
response_class = ServerErrorTemplateResponse
template_name = "error/generic.html"
2019-03-22 11:16:30 +00:00
2019-04-09 15:26:53 +00:00
# pylint: disable=useless-super-delegation
def dispatch(self, *args, **kwargs): # pragma: no cover
2019-04-09 15:26:53 +00:00
"""Little wrapper so django accepts this function"""
return super().dispatch(*args, **kwargs)