From 246a39df9a347a09f0bc45ba75910b48e2ce87eb Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 16 Jan 2019 11:59:38 +0000 Subject: [PATCH] Add in a custom template for the apply 404 --- opentech/apply/urls.py | 11 +++++++++++ opentech/apply/utils/__init__.py | 1 + opentech/apply/utils/app.py | 6 ++++++ opentech/apply/utils/templates/apply/404.html | 13 +++++++++++++ opentech/apply/utils/views.py | 5 +++++ opentech/settings/base.py | 1 + 6 files changed, 37 insertions(+) create mode 100644 opentech/apply/utils/app.py create mode 100644 opentech/apply/utils/templates/apply/404.html diff --git a/opentech/apply/urls.py b/opentech/apply/urls.py index 662aa72b2..deb327004 100644 --- a/opentech/apply/urls.py +++ b/opentech/apply/urls.py @@ -1,5 +1,7 @@ +from django.conf import settings from django.urls import include, path +from .utils import views from .users import urls as users_urls from .dashboard import urls as dashboard_urls @@ -14,4 +16,13 @@ urlpatterns = [ path('hijack/', include('hijack.urls', 'hijack')), ] +if settings.DEBUG: + urlpatterns += [ + # Add views for testing 404 and 500 templates + path('test404/', views.page_not_found), + ] + urlpatterns += base_urlpatterns + + +handler404 = 'opentech.apply.utils.views.page_not_found' diff --git a/opentech/apply/utils/__init__.py b/opentech/apply/utils/__init__.py index e69de29bb..406254cfe 100644 --- a/opentech/apply/utils/__init__.py +++ b/opentech/apply/utils/__init__.py @@ -0,0 +1 @@ +default_app_config = 'opentech.apply.utils.app.UtilsConfig' diff --git a/opentech/apply/utils/app.py b/opentech/apply/utils/app.py new file mode 100644 index 000000000..b7215b4e1 --- /dev/null +++ b/opentech/apply/utils/app.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class UtilsConfig(AppConfig): + name = 'opentech.apply.utils' + label = 'apply_utils' diff --git a/opentech/apply/utils/templates/apply/404.html b/opentech/apply/utils/templates/apply/404.html new file mode 100644 index 000000000..30b1072c3 --- /dev/null +++ b/opentech/apply/utils/templates/apply/404.html @@ -0,0 +1,13 @@ +{% extends "base-apply.html" %} +{% load wagtailcore_tags wagtailsettings_tags %} + +{% block title %}{{ settings.utils.SystemMessagesSettings.title_404 }}{% endblock %} + +{% block body_class %}template-404{% endblock %} + +{% block content %} +<div class="wrapper wrapper--small wrapper--inner-space-large"> + <h1>{{ settings.utils.SystemMessagesSettings.title_404 }}</h1> + {{ settings.utils.SystemMessagesSettings.body_404|richtext }} +</div> +{% endblock %} diff --git a/opentech/apply/utils/views.py b/opentech/apply/utils/views.py index d77666e5a..41a7a01de 100644 --- a/opentech/apply/utils/views.py +++ b/opentech/apply/utils/views.py @@ -1,10 +1,15 @@ from django.contrib.auth.decorators import login_required from django.utils.decorators import method_decorator +from django.views import defaults from django.views.generic import DetailView, View from django.views.generic.detail import SingleObjectTemplateResponseMixin from django.views.generic.edit import ModelFormMixin, ProcessFormView +def page_not_found(request, exception=None, template_name='apply/404.html'): + return defaults.page_not_found(request, exception, template_name) + + @method_decorator(login_required, name='dispatch') class ViewDispatcher(View): admin_view: View = None diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 12e28fd06..b84356011 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -73,6 +73,7 @@ INSTALLED_APPS = [ 'opentech.apply.review', 'opentech.apply.determinations', 'opentech.apply.stream_forms', + 'opentech.apply.utils', 'opentech.public.funds', 'opentech.public.home', -- GitLab