Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore:enhance search CSV download to include multiple doc types. #31

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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