-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Populate domains drop down with what's been ingested in datahub (#407)
* Add missing domain information from charts * Update search tests that hit datahub dev - remove entity which is not currently present - enable the no_duplicates test (we have fixed this) * Load the list of domains from Datahub Previously we hardcoded the list of domains shown in the search filter, and had different lists per environment. This was useful in alpha when we had some junk domains we wanted to filter out, but now we're at a point where every domain in Datahub should be one we want to use. This commit means we now fetch every domain that has something linked to it, and display that in alphabetical order. * Move domain model to models and remove unused model * Refacotr: decouple SearchFacetFetcher from DomainModel * Cache facets fetched from datahub Ideally we would just fetch the facets once per request, but in practice we do this from a few different places. 1. In the view we instantiate a SearchService, which uses the domain model in constructing filters for Datahub. 2. The SearchForm also needs them to know what choices are valid, so we need to pass a callback to the form's ChoiceField. That callback does not share any data with the view. Caching the value is a quick way to avoid making extra requests for the same data. * Hide subdomains if there aren't any defined This is the case at the moment, because the domain model we've pulled in from CaDeT doesn't have subdomains. This might change later though so I don't want to remove the subdomain code completely. * Include missing domains Previously it was only returning domains with tables in. We should include any that show as non-empty in Find MOJ Data.
- Loading branch information
Showing
20 changed files
with
203 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generated by Django 5.0.6 on 2024-06-10 09:39 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("home", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="Catalogue", | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
from typing import NamedTuple | ||
|
||
from data_platform_catalogue.search_types import SearchFacets | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Domain(NamedTuple): | ||
urn: str | ||
label: str | ||
|
||
|
||
class DomainModel: | ||
""" | ||
Store information about domains and subdomains | ||
""" | ||
|
||
def __init__(self, search_facets: SearchFacets): | ||
self.labels = {} | ||
|
||
self.top_level_domains = [ | ||
Domain(option.value, option.label) | ||
for option in search_facets.options("domains") | ||
] | ||
self.top_level_domains.sort(key=lambda d: d.label) | ||
|
||
logger.info(f"{self.top_level_domains=}") | ||
|
||
self.subdomains = {} | ||
|
||
for urn, label in self.top_level_domains: | ||
self.labels[urn] = label | ||
|
||
def all_subdomains(self) -> list[Domain]: # -> list[Any] | ||
""" | ||
A flat list of all subdomains | ||
""" | ||
subdomains = [] | ||
for domain_choices in self.subdomains.values(): | ||
subdomains.extend(domain_choices) | ||
return subdomains | ||
|
||
def get_parent_urn(self, child_subdomain_urn) -> str | None: | ||
for domain, subdomains in self.subdomains.items(): | ||
for subdomain in subdomains: | ||
if child_subdomain_urn == subdomain.urn: | ||
return domain | ||
|
||
def get_label(self, urn): | ||
return self.labels.get(urn, urn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from data_platform_catalogue.search_types import SearchFacets | ||
from django.core.cache import cache | ||
|
||
from .base import GenericService | ||
|
||
|
||
class SearchFacetFetcher(GenericService): | ||
def __init__(self): | ||
self.client = self._get_catalogue_client() | ||
self.cache_key = "search_facets" | ||
self.cache_timeout_seconds = 5 | ||
|
||
def fetch(self) -> SearchFacets: | ||
""" | ||
Fetch a static list of options that is independent of the search query | ||
and any applied filters. Values are cached for 5 seconds to avoid | ||
unnecessary queries. | ||
""" | ||
result = cache.get(self.cache_key) | ||
if not result: | ||
result = self.client.search_facets() | ||
cache.set(self.cache_key, result, timeout=self.cache_timeout_seconds) | ||
|
||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.