diff --git a/passbook/core/templates/error/400.html b/passbook/core/templates/error/400.html new file mode 100644 index 000000000..b4f02ecfd --- /dev/null +++ b/passbook/core/templates/error/400.html @@ -0,0 +1,26 @@ +{% extends 'login/base.html' %} + +{% load static %} +{% load i18n %} +{% load utils %} + +{% block head %} +{{ block.super }} + +{% endblock %} + +{% block card %} +
+

{% trans 'Bad Request' %}

+
+
+ {% if 'back' in request.GET %} + {% trans 'Back' %} + {% endif %} +
+{% endblock %} diff --git a/passbook/core/templates/error/403.html b/passbook/core/templates/error/403.html new file mode 100644 index 000000000..7aaebb64c --- /dev/null +++ b/passbook/core/templates/error/403.html @@ -0,0 +1,26 @@ +{% extends 'login/base.html' %} + +{% load static %} +{% load i18n %} +{% load utils %} + +{% block head %} +{{ block.super }} + +{% endblock %} + +{% block card %} +
+

{% trans 'Forbidden' %}

+
+
+ {% if 'back' in request.GET %} + {% trans 'Back' %} + {% endif %} +
+{% endblock %} diff --git a/passbook/core/templates/error/404.html b/passbook/core/templates/error/404.html new file mode 100644 index 000000000..3dcfbb5cc --- /dev/null +++ b/passbook/core/templates/error/404.html @@ -0,0 +1,26 @@ +{% extends 'login/base.html' %} + +{% load static %} +{% load i18n %} +{% load utils %} + +{% block head %} +{{ block.super }} + +{% endblock %} + +{% block card %} +
+

{% trans 'Not Found' %}

+
+
+ {% if 'back' in request.GET %} + {% trans 'Back' %} + {% endif %} +
+{% endblock %} diff --git a/passbook/core/templates/error/500.html b/passbook/core/templates/error/500.html new file mode 100644 index 000000000..4aa544a6f --- /dev/null +++ b/passbook/core/templates/error/500.html @@ -0,0 +1,26 @@ +{% extends 'login/base.html' %} + +{% load static %} +{% load i18n %} +{% load utils %} + +{% block head %} +{{ block.super }} + +{% endblock %} + +{% block card %} +
+

{% trans 'Server Error' %}

+
+
+ {% if 'back' in request.GET %} + {% trans 'Back' %} + {% endif %} +
+{% endblock %} diff --git a/passbook/core/urls.py b/passbook/core/urls.py index 3227ad273..61461cb06 100644 --- a/passbook/core/urls.py +++ b/passbook/core/urls.py @@ -7,13 +7,18 @@ from django.urls import include, path from django.views.generic import RedirectView from passbook.core.auth import view -from passbook.core.views import authentication, overview, user +from passbook.core.views import authentication, error, overview, user from passbook.lib.utils.reflection import get_apps LOGGER = getLogger(__name__) admin.autodiscover() admin.site.login = RedirectView.as_view(pattern_name='passbook_core:auth-login') +handler400 = error.BadRequestView.as_view() +handler403 = error.ForbiddenView.as_view() +handler404 = error.NotFoundView.as_view() +handler500 = error.BadRequestView.as_view() + core_urls = [ # Authentication views path('auth/login/', authentication.LoginView.as_view(), name='auth-login'), diff --git a/passbook/core/views/error.py b/passbook/core/views/error.py new file mode 100644 index 000000000..ccfec9833 --- /dev/null +++ b/passbook/core/views/error.py @@ -0,0 +1,60 @@ +"""passbook core error views""" + +from django.http.response import (HttpResponseBadRequest, + HttpResponseForbidden, HttpResponseNotFound, + HttpResponseServerError) +from django.template.response import TemplateResponse +from django.views.generic import TemplateView + + +class BadRequestTemplateResponse(TemplateResponse, HttpResponseBadRequest): + """Combine Template response with Http Code 400""" + +class ForbiddenTemplateResponse(TemplateResponse, HttpResponseForbidden): + """Combine Template response with Http Code 403""" + +class NotFoundTemplateResponse(TemplateResponse, HttpResponseNotFound): + """Combine Template response with Http Code 404""" + +class ServerErrorTemplateResponse(TemplateResponse, HttpResponseServerError): + """Combine Template response with Http Code 500""" + +class BadRequestView(TemplateView): + """Show Bad Request message""" + + response_class = BadRequestTemplateResponse + template_name = 'error/400.html' + + extra_context = { + 'is_login': True + } + +class ForbiddenView(TemplateView): + """Show Forbidden message""" + + response_class = ForbiddenTemplateResponse + template_name = 'error/403.html' + + extra_context = { + 'is_login': True + } + +class NotFoundView(TemplateView): + """Show Not Found message""" + + response_class = NotFoundTemplateResponse + template_name = 'error/404.html' + + extra_context = { + 'is_login': True + } + +class ServerErrorView(TemplateView): + """Show Server Error message""" + + response_class = ServerErrorTemplateResponse + template_name = 'error/500.html' + + extra_context = { + 'is_login': True + }