Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom error pages #286

Draft
wants to merge 13 commits into
base: live
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:

- name: Run tests
run: |
docker compose exec django pytest -v
docker compose exec django pytest -vv
1 change: 1 addition & 0 deletions project/npda/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
{% block toasts %}
{% include 'toasts.html' %}
{% endblock %}

<div>
{% block content %}{% endblock %}
</div>
Expand Down
11 changes: 11 additions & 0 deletions project/npda/templates/errors/400.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "errors/error_base.html" %}

{% block error_number %}
400
{% endblock %}

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but the server will
not/cannot process your request. This may be due to a client error or a malformed request. <br> Please try again.
</p>
{% endblock %}
10 changes: 10 additions & 0 deletions project/npda/templates/errors/403.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "errors/error_base.html" %}

{% block error_number %}
403
{% endblock %}

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but you need
authorisation to view that page. <br> Please log in and try again.</p>
{% endblock %}
11 changes: 11 additions & 0 deletions project/npda/templates/errors/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "errors/error_base.html" %}

{% block error_number %}
404
{% endblock %}

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but the page
you requested does not exist or the link is broken. <br> Please check the web
address and try again.</p>
{% endblock %}
11 changes: 11 additions & 0 deletions project/npda/templates/errors/500.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "errors/error_base.html" %}

{% block error_number %}
500
{% endblock %}

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but there was
an internal server error. <br> Please retry your request. If the issue persists, please report this type of
error to the team.</p>
{% endblock %}
10 changes: 10 additions & 0 deletions project/npda/templates/errors/csrf_fail.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "errors/error_base.html" %}

{% block error_number %}
CSRF Failure
{% endblock %}

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but validation of
the CSRF token failed. <br> Please log out and retry your request. </p>
{% endblock %}
26 changes: 26 additions & 0 deletions project/npda/templates/errors/error_base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{% extends "base.html" %}
{% load static %}

{% block content %}
<section class="bg-rcpch_dark_blue font-montserrat">
<div class="py-8 px-4 mx-auto max-w-screen-xl text-center lg:py-16 lg:px-12">
<h1
class="mb-4 text-4xl font-extrabold font-arial tracking-tight leading-none text-gray-900 md:text-5xl lg:text-6xl text-white">
Oops... There was an error</h1>
<h2 class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">Error Status Code:
{% block error_number %}
Null
{% endblock %}
</h2>
<div class="flex flex-col mb-8 lg:mb-16 space-y-4 sm:flex-row sm:justify-center sm:space-y-0 sm:space-x-4">

{% block error_msg %}
<p class="mb-8 text-lg font-normal lg:text-xl sm:px-16 xl:px-48 text-white">We're sorry about this, but there was
an error.</p>
{% endblock %}

</div>
</div>
</section>

{% endblock %}
32 changes: 9 additions & 23 deletions project/npda/templatetags/npda_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,12 @@ def patient_valid(patient):
# Used to keep text highlighted in navbar for the tab that has been selected
@register.simple_tag
def active_navbar_tab(request, url_name):
return (
"text-rcpch_light_blue"
if request.resolver_match.url_name == url_name
else "text-gray-700"
)


@register.filter
def join_by_comma(queryset):
if len(queryset) == 0:
return "No patients"
return ", ".join(map(str, queryset.values_list("nhs_number", flat=True)))


@register.filter
def extract_digits(value, underscore_index=0):
"""
Extracts all digits between the second or subsequent pair of _ characters in the string.
"""
matches = re.findall(r"_(\d+)", value)
if len(matches) > 0:
return int(matches[underscore_index])
return 0
if request.resolver_match is not None:
return (
"text-rcpch_light_blue"
if request.resolver_match.url_name == url_name
else "text-gray-700"
)
else:
# Some routes, such as Error 404, do not have resolver_match property.
return "text-gray-700"
Loading
Loading