Skip to content

Commit

Permalink
feat:delete outdated construction-data.csv
Browse files Browse the repository at this point in the history
Removed construction-data.csv from the orp_search directory. The file contained deprecated safety and regulation guidance for various construction topics, which are now available in updated formats elsewhere in the project.
  • Loading branch information
hareshkainthdbt committed Oct 14, 2024
1 parent 3eb8fed commit ee5bcf5
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 56 deletions.
2 changes: 1 addition & 1 deletion orp/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
path("", orp_search_views.search, name="search"),
# If we choose to have a start page with green button, this is it:
# path("", core_views.home, name="home"),
path("details/", orp_search_views.details, name="details"),
path("details/<str:id>", orp_search_views.details, name="details"),
path("healthcheck/", core_views.health_check, name="healthcheck"),
path(
"accessibility-statement/",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
from io import StringIO

import pandas as pd

# flake8: noqa

construction_data_csv = """
id,title,identifier,publisher,language,format,description,date_issued,date_modified,date_valid,audience,coverage,subject,type,license,regulatory_topics,status,date_uploaded_to_orp,has_format,is_format_of,has_version,is_version_of,references,is_referenced_by,has_part,is_part_of,is_replaced_by,replaces,related_legislation
Nt6Ft0Dt,Introduction to asbestos safety,https://www.hse.gov.uk/asbestos/introduction/index.htm,Health and Safety Executive,eng,HTML,"The guidance summarises what you should do to comply with the law, including:
Expand Down Expand Up @@ -7268,3 +7275,14 @@
Planning
Transport",,,,,,,,,,,,,"https://www.legislation.gov.uk/ukpga/2008/29
https://www.legislation.gov.uk/uksi/2013/1883/article/3/made"
"""


def get_construction_data_as_dataframe():
# Use StringIO to convert the CSV string into a file-like object
csv_file_like_object = StringIO(construction_data_csv)

# Read the data into a pandas DataFrame
df = pd.read_csv(csv_file_like_object)

return df
6 changes: 4 additions & 2 deletions orp/orp_search/public_gateway.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

import pandas as pd
import requests # type: ignore

from jinja2 import Template
from orp_search.config import SearchDocumentConfig
from orp_search.dummy_data import get_construction_data_as_dataframe

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -72,9 +72,11 @@ def search(self, config: SearchDocumentConfig):
# If the dummy flag is set, return dummy data. Ideally, this will be
# removed from the final implementation
if config.dummy:
df = pd.read_csv("orp/orp_search/construction-data.csv")
df = get_construction_data_as_dataframe()

if config.id:
logger.info("using dummy data")

# Fetch the record with the specified id
record = df[df["id"] == config.id].to_dict(orient="records")
if record:
Expand Down
32 changes: 12 additions & 20 deletions orp/orp_search/templates/details.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,20 @@
<a class="govuk-breadcrumbs__link" href="#">Search results</a>
</li>
<li class="govuk-breadcrumbs__list-item">
<a class="govuk-breadcrumbs__link" href="#">SR2015 No 39: use of waste in a deposit for recovery operations</a>
<a class="govuk-breadcrumbs__link" href="#">{{ result.title }}</a>
</li>
</ol>
</nav>
<main class="govuk-main-wrapper govuk-main-wrapper--l" id="main-content" role="main">
<div class="govuk-grid-row govuk-!-margin-bottom-4">
<div class="govuk-grid-column-three-quarters">
<h1 class="govuk-heading-xl">SR2015 No 39: use of waste in a deposit for recovery operations</h1>
<h1 class="govuk-heading-xl">{{ result.title }}</h1>
</div>
</div>
<div class="govuk-grid-row govuk-body">
<div class="govuk-grid-column-three-quarters">
<p class="govuk-body">
These standard rules allow you to store and use waste in a deposit for recovery activities involving
construction, reclamation, restoration or improvement of land other than by mobile plant.
</p>
<p class="govuk-body">
These standard rules are for the recovery of waste only and do not apply to any activities involving disposal.
{{ result.description }}
</p>
<h2 class="govuk-heading-m">Document details</h2>
<dl class="govuk-summary-list">
Expand All @@ -37,57 +33,53 @@ <h2 class="govuk-heading-m">Document details</h2>
Link to document on publisher’s website
</dt>
<dd class="govuk-summary-list__value">
<a class="govuk-link" href="#">SR2015 No 39: use of waste in a deposit for recovery operations</a>
<a class="govuk-link" href="{{ result.identifier }}">{{ result.title }}</a>
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Document type
</dt>
<dd class="govuk-summary-list__value">
Guidance
{{ result.type }}
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Date published
</dt>
<dd class="govuk-summary-list__value">
2 February 2016
{{ result.date_issued }}
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Last updated
</dt>
<dd class="govuk-summary-list__value">
3 April 2019
{{ result.date_modified }}
</dd>
</div>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
Published by
</dt>
<dd class="govuk-summary-list__value">
Environment Agency
{{ result.publisher }}
</dd>
</div>
</dl>
<h2 class="govuk-heading-m">Related content on legislation.gov.uk</h2>
<p class="govuk-body">
<a class="govuk-link" href="#">Wildlife and Countryside Act 1981</a>
</p>
<p class="govuk-body">
<a class="govuk-link" href="#">Countryside and Rights of Way Act 2000</a>
<a class="govuk-link" href="#">{{ result.related_legislation }}</a>
</p>

<h2 class="govuk-heading-m">Regulatory topics</h2>
<ul class="govuk-list orp-topics-list">
<li class="govuk-body-s orp-secondary-text-colour">
Waste
</li>
<li class="govuk-body-s orp-secondary-text-colour">
Recycling
{% for topic in result.regulatory_topics %}
<p>{{ topic }}</p>
{% endfor %}
</li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion orp/orp_search/templates/orp.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ <h2 class="govuk-fieldset__heading">
<div class="govuk-summary-list__row--no-border">
<span class="govuk-caption-m">{{ result.document_type }}</span>
<h2 class="govuk-heading-m">
<a href="/document/{{ result.id }}" class="govuk-link">
<a href="/details/{{ result.id }}" class="govuk-link">
{{result.title}}
</a>
</h2>
Expand Down
49 changes: 17 additions & 32 deletions orp/orp_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@require_http_methods(["GET"])
def document(request: HttpRequest) -> HttpResponse:
def details(request: HttpRequest, id) -> HttpResponse:
"""Details view.
Handles the GET request to fetch details based on the provided id.
Expand All @@ -23,36 +23,33 @@ def document(request: HttpRequest) -> HttpResponse:
"service_name": settings.SERVICE_NAME_SEARCH,
}

# Create a new instance of the RegulationSearchForm
form = RegulationSearchForm(request.GET or None)

# Extract the id parameter from the request
document_id = form.cleaned_data.get("id")
document_id = id
logger.info("document id: %s", document_id)
if not document_id:
context["error"] = "no document id provided"
return render(
request, template_name="orp_details.html", context=context
)
return render(request, template_name="details.html", context=context)

# Create a SearchDocumentConfig instance and set the id parameter
config = SearchDocumentConfig(search_terms="", id=document_id)
config = SearchDocumentConfig(search_terms="", dummy=True, id=document_id)

# Use the PublicGateway class to fetch the details
public_gateway = PublicGateway()
try:
search_results = public_gateway.search(config)
logger.info("search results: %s", search_results)
search_results = search_results[0] if search_results else {}
context["results"] = search_results
return render(
request, template_name="orp_details.html", context=context
)
search_result = public_gateway.search(config)
logger.info("search result: %s", search_result)

if "regulatory_topics" in search_result:
search_result["regulatory_topics"] = search_result[
"regulatory_topics"
].split("\n")

context["result"] = search_result
return render(request, template_name="details.html", context=context)
except Exception as e:
logger.error("Error fetching details: %s", e)
logger.error("error fetching details: %s", e)
context["error"] = f"error fetching details: {e}"
return render(
request, template_name="orp_details.html", context=context
)
return render(request, template_name="details.html", context=context)


@require_http_methods(["GET"])
Expand Down Expand Up @@ -157,15 +154,3 @@ def search(request: HttpRequest) -> HttpResponse:
logger.info("search results page total: %s", context["results_page_total"])
logger.debug("paginated search results: %s", paginated_search_results)
return render(request, template_name="orp.html", context=context)


@require_http_methods(["GET"])
def details(request: HttpRequest) -> HttpResponse:
"""Regulation details.
Returns regulation details page.
"""
context = {
"service_name": settings.SERVICE_NAME,
}
return render(request, template_name="details.html", context=context)

0 comments on commit ee5bcf5

Please sign in to comment.