From ba933de75ec1d5ddd7115eadcf616034268db04b Mon Sep 17 00:00:00 2001 From: Nick Jackson Date: Thu, 24 Oct 2024 16:10:02 +0100 Subject: [PATCH] Swap to using new in-API XSLT transformation This now leans on using the XSLT for body transformation which exists within the API, rather than making a call out to MarkLogic. --- .../templates/judgment/full_text_html.html | 2 +- judgments/tests/test_judgments.py | 14 ++++++-------- judgments/utils/view_helpers.py | 4 +++- judgments/views/document_full_text.py | 6 ------ 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ds_caselaw_editor_ui/templates/judgment/full_text_html.html b/ds_caselaw_editor_ui/templates/judgment/full_text_html.html index 35de15c6c..e73197d52 100644 --- a/ds_caselaw_editor_ui/templates/judgment/full_text_html.html +++ b/ds_caselaw_editor_ui/templates/judgment/full_text_html.html @@ -28,7 +28,7 @@

Error log

class="document-navigation-links"> Back to start - {{ document_html_content }} + {{ document_html }} {% include "includes/judgment_end_document_marker.html" %}
{% endautoescape %} diff --git a/judgments/tests/test_judgments.py b/judgments/tests/test_judgments.py index 5a7392fa3..c03c5458e 100644 --- a/judgments/tests/test_judgments.py +++ b/judgments/tests/test_judgments.py @@ -19,8 +19,10 @@ def test_judgment_html_view(self, document_type, document_exists, mock_judgment) judgment = JudgmentFactory.build( uri="hvtest/4321/123", - html="

Test Judgment

", - body=DocumentBodyFactory.build(name="Test v Tested"), + body=DocumentBodyFactory.build( + name="Test v Tested", + xml_string="This is our test judgment.", + ), ) judgment.body.document_date_as_date = date(1999, 10, 31) mock_judgment.return_value = judgment @@ -35,7 +37,7 @@ def test_judgment_html_view(self, document_type, document_exists, mock_judgment) decoded_response = response.content.decode("utf-8") assert "Test v Tested" in decoded_response - assert "

Test Judgment

" in decoded_response + assert "This is our test judgment." in decoded_response assert "31 Oct 1999" in decoded_response assert response.status_code == 200 @@ -53,8 +55,7 @@ def test_judgment_html_view_with_parser_failure( judgment = JudgmentFactory.build( uri="hvtest/4321/123", - html="

Test Judgment

", - body=DocumentBodyFactory.build(html="

Test Judgment

", xml_string="Error log"), + body=DocumentBodyFactory.build(xml_string="Error log"), ) assert judgment.body.failed_to_parse @@ -73,9 +74,6 @@ def test_judgment_html_view_with_parser_failure( assert "<error>Error log</error>" in decoded_response assert "Error log" not in decoded_response - assert "<h1>Test Judgment</h1>" not in decoded_response - assert "

Test Judgment

" not in decoded_response - assert response.status_code == 200 def test_judgment_html_view_redirect(self): diff --git a/judgments/utils/view_helpers.py b/judgments/utils/view_helpers.py index 4b004b963..60c474010 100644 --- a/judgments/utils/view_helpers.py +++ b/judgments/utils/view_helpers.py @@ -90,7 +90,9 @@ def get_context_data(self, **kwargs): if version_uri: context["current_version_number"] = extract_version_number_from_filename(version_uri) - context["requested_version"] = get_document_by_uri_or_404(version_uri) + context["document_html"] = get_document_by_uri_or_404(version_uri).body.content_as_html + else: + context["document_html"] = document.body.content_as_html # TODO: Remove this once we fully deprecate 'judgment' contexts context["judgment"] = document diff --git a/judgments/views/document_full_text.py b/judgments/views/document_full_text.py index 7e620ad41..1f87f372c 100644 --- a/judgments/views/document_full_text.py +++ b/judgments/views/document_full_text.py @@ -13,13 +13,7 @@ class DocumentReviewHTMLView(DocumentView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - if not context["document"].body.failed_to_parse: - context["document_html_content"] = context["document"].content_as_html( - version_uri=context["requested_version"].uri if "requested_version" in context else None, - ) - context["view"] = "judgment_html" - context["corrected_ncn_url"] = get_corrected_ncn_url(context["judgment"]) return context