Skip to content

Commit

Permalink
chore:enhance search CSV download to include multiple doc types.
Browse files Browse the repository at this point in the history
Updated the `download_search_csv` function to handle multiple document types for both public gateway and legislation searches. This includes collecting results from different sources and combining them before generating the CSV.
  • Loading branch information
hareshkainthdbt committed Oct 17, 2024
1 parent 0f600a8 commit 341d998
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions orp/orp_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _decode_url(encoded_url):
@require_http_methods(["GET"])
def download_search_csv(request: HttpRequest) -> HttpResponse:
search_terms = request.GET.get("search", "")
document_type_terms = request.GET.get("document_type", "")
document_type_terms = request.GET.getlist("document_type", "")
publisher_terms = request.GET.getlist("publisher", None)
sort_by = request.GET.get("sort", None)

Expand All @@ -90,8 +90,53 @@ def download_search_csv(request: HttpRequest) -> HttpResponse:
if sort_by:
config.sort_by = sort_by

public_gateway = PublicGateway()
search_results = public_gateway.search(config)
public_gateway_search_results = []
legislation_search_results = []

if (
not config.document_types
or "standard" in config.document_types
or "guidance" in config.document_types
):
public_gateway = PublicGateway()
public_gateway_search_results = public_gateway.search(config)

# Legislation search
# If config.search_terms is empty then we don't need to
# search for legislation
if (
"" not in config.search_terms
and not config.document_types
or "legislation" in config.document_types
):
legislation = Legislation()
legislation_search_results = legislation.search(config)

search_results = []

for result in public_gateway_search_results:
search_results.append(
{
"id": result["id"],
"title": result["title"],
"publisher": result["publisher"],
"description": result["description"],
"type": result["type"],
"date_modified": result["date_modified"],
}
)

for result in legislation_search_results:
search_results.append(
{
"id": result["id"],
"title": result["title"],
"publisher": result["publisher"],
"description": "",
"type": result["type"],
"date_modified": result["date_modified"],
}
)

# Convert search_results JSON object to DataFrame
# (for demonstration purposes)
Expand Down

0 comments on commit 341d998

Please sign in to comment.