generated from nationalarchives/django-application-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* FIND-81:remove search details path * FIND-81:record details initial
- Loading branch information
Showing
16 changed files
with
169 additions
and
4 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.shortcuts import render | ||
|
||
|
||
def custom_404_error_view(request, exception=None): | ||
response = render(request, "404.html") | ||
response.status_code = 404 | ||
return response |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.urls.converters import StringConverter | ||
|
||
|
||
class IDConverter(StringConverter): | ||
"""Converter used to extract id's from a URL.""" | ||
|
||
regex = r"([ACDFN][0-9]{1,8}|[a-f0-9]{8}-?([a-f0-9]{4}-?){3}[a-f0-9]{12}(_[1-9])?)" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from django.shortcuts import Http404 | ||
from django.template.response import TemplateResponse | ||
|
||
|
||
def record_detail_view(request, id): | ||
""" | ||
View for rendering a record's details page. | ||
""" | ||
template_name = "records/record_detail.html" | ||
context = {} | ||
page_type = "Record details page" | ||
|
||
page_title = f"Catalogue ID: {id}" | ||
|
||
context.update( | ||
page_type=page_type, | ||
page_title=page_title, | ||
) | ||
|
||
return TemplateResponse( | ||
request=request, template=template_name, context=context | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% extends 'base.html' %} | ||
|
||
{% block content %} | ||
<div class="tna-section"> | ||
<div class="tna-container"> | ||
<div class="tna-column tna-column--width-2-3 tna-column--width-5-6-medium tna-column--full-small tna-column--full-tiny"> | ||
<h1 class="tna-heading-xl">Page Not Found</h1> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} |
3 changes: 1 addition & 2 deletions
3
app/templates/search/catalogue/item.html → app/templates/records/record_detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import re | ||
|
||
from app.records.converters import IDConverter | ||
from django.test import SimpleTestCase | ||
|
||
|
||
class TestIDFormats(SimpleTestCase): | ||
def test_valid_formats(self): | ||
for label, value in ( | ||
("longformat", "3717ee38900740728076a61a398fcb84"), | ||
("guid", "4d8dae2c-b417-4614-8ed8-924b9b4beeac"), | ||
("dri_guid_plus", "00149557ca64456a8a41e44f14621801_1"), | ||
("iaid_A", "A13530124"), | ||
("iaid_C", "C2341693"), | ||
("iaid_D", "D431198"), | ||
("iaid_F", "F257629"), | ||
("iaid_N", "N14562581"), | ||
): | ||
id_regex = re.compile(IDConverter.regex) | ||
with self.subTest(label): | ||
self.assertTrue(id_regex.match(value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from django.test import TestCase | ||
from django.urls import resolve, reverse | ||
|
||
|
||
class TestMachineReadableDetailsRouteResolution(TestCase): | ||
def test_resolves_iaid(self): | ||
resolver = resolve("/catalogue/id/C7810139/") | ||
|
||
self.assertEqual(resolver.view_name, "details-page-machine-readable") | ||
self.assertEqual(resolver.kwargs["id"], "C7810139") | ||
|
||
def test_iaid_with_non_standard_prefix(self): | ||
resolver = resolve("/catalogue/id/C123456/") | ||
|
||
self.assertEqual(resolver.view_name, "details-page-machine-readable") | ||
self.assertEqual(resolver.kwargs["id"], "C123456") | ||
|
||
def test_resolves_uuid(self): | ||
# Some IAIDs are UUIDs. Tested IAID is a real example | ||
resolver = resolve( | ||
"/catalogue/id/43f766a9-e968-4b82-93dc-8cf11a841d41/" | ||
) | ||
|
||
self.assertEqual(resolver.view_name, "details-page-machine-readable") | ||
self.assertEqual( | ||
resolver.kwargs["id"], "43f766a9-e968-4b82-93dc-8cf11a841d41" | ||
) | ||
|
||
|
||
class TestMachineReadableDetailsURL(TestCase): | ||
def test_reverse_iaid(self): | ||
url = reverse( | ||
"details-page-machine-readable", kwargs={"id": "C7810139"} | ||
) | ||
|
||
self.assertEqual(url, "/catalogue/id/C7810139/") | ||
|
||
def test_reverse_uuid(self): | ||
url = reverse( | ||
"details-page-machine-readable", | ||
kwargs={"id": "43f766a9-e968-4b82-93dc-8cf11a841d41"}, | ||
) | ||
|
||
self.assertEqual( | ||
url, "/catalogue/id/43f766a9-e968-4b82-93dc-8cf11a841d41/" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.test import TestCase | ||
|
||
|
||
class TestRecordView(TestCase): | ||
|
||
def test_no_matches_respond_with_404(self): | ||
|
||
response = self.client.get("/catalogue/id/Z123456/") | ||
|
||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_record_rendered_for_single_result(self): | ||
|
||
response = self.client.get("/catalogue/id/C123456/") | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual( | ||
response.resolver_match.view_name, "details-page-machine-readable" | ||
) | ||
self.assertTemplateUsed("records/record_detail.html") |