Skip to content

Commit

Permalink
Reformats and displays related legislation as titles rather than urls
Browse files Browse the repository at this point in the history
  • Loading branch information
gdbarnes committed Dec 16, 2024
1 parent 14c4477 commit 7041fcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
12 changes: 4 additions & 8 deletions app/search/templates/document.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,13 @@ <h2 class="govuk-heading-m">Document details</h2>
</div>
</dl>

{% if 'nan' not in result.related_legislation %}
{% if result.related_legislation and 'nan' not in result.related_legislation %}
<h2 class="govuk-heading-m">Related content on legislation.gov.uk</h2>
<!--
The design shows these links as document titles which we don't have.
We'd need to look up each one using the legislation.gov.uk API
-->
<div class="govuk-!-margin-bottom-6">
{% for legislation in result.related_legislation %}
<p class="govuk-body govuk-!-margin-bottom-2">
<a class="govuk-link" href="{{legislation}}">{{ legislation }}</a>
</p>
<p class="govuk-body govuk-!-margin-bottom-2">
<a class="govuk-link" href="{{ legislation.url }}">{{ legislation.title }}</a>
</p>
{% endfor %}
</div>
{% endif %}
Expand Down
19 changes: 16 additions & 3 deletions app/search/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import csv
import json
import logging

from django.conf import settings
Expand Down Expand Up @@ -38,9 +39,21 @@ def document(request: HttpRequest, id) -> HttpResponse:
context["result"].regulatory_topics = context[
"result"
].regulatory_topics.split("\n")
context["result"].related_legislation = context[
"result"
].related_legislation.split("\n")

# Parse the related_legislation field
related_legislation_str = context["result"].related_legislation
try:
related_legislation_double_quotes = (
related_legislation_str.replace("'", '"')
)
related_legislation_json = json.loads(
related_legislation_double_quotes
)
context["result"].related_legislation = related_legislation_json
except json.JSONDecodeError as e:
logger.error(f"JSON decoding error: {e}")
context["result"].related_legislation = []

except Exception as e:
logger.error("error fetching details: %s", e)
context["error"] = f"error fetching details: {e}"
Expand Down

0 comments on commit 7041fcf

Please sign in to comment.