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-02-21 14:04:37 +00:00
|
|
|
extra_context = {"card_title": "Bad Request"}
|
|
|
|
|
2019-03-22 11:16:30 +00:00
|
|
|
response_class = BadRequestTemplateResponse
|
2020-02-21 14:04:37 +00:00
|
|
|
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-02-21 14:04:37 +00:00
|
|
|
extra_context = {"card_title": "Forbidden"}
|
|
|
|
|
2019-03-22 11:16:30 +00:00
|
|
|
response_class = ForbiddenTemplateResponse
|
2020-02-21 14:04:37 +00:00
|
|
|
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-02-21 14:04:37 +00:00
|
|
|
extra_context = {"card_title": "Not Found"}
|
|
|
|
|
2019-03-22 11:16:30 +00:00
|
|
|
response_class = NotFoundTemplateResponse
|
2020-02-21 14:04:37 +00:00
|
|
|
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-02-21 14:04:37 +00:00
|
|
|
extra_context = {"card_title": "Server Error"}
|
|
|
|
|
2019-03-22 11:16:30 +00:00
|
|
|
response_class = ServerErrorTemplateResponse
|
2020-02-21 14:04:37 +00:00
|
|
|
template_name = "error/generic.html"
|
2019-03-22 11:16:30 +00:00
|
|
|
|
2019-04-09 16:26:53 +01:00
|
|
|
# pylint: disable=useless-super-delegation
|
|
|
|
def dispatch(self, *args, **kwargs):
|
|
|
|
"""Little wrapper so django accepts this function"""
|
|
|
|
return super().dispatch(*args, **kwargs)
|