Skip to content

Commit

Permalink
Filters out deprecated places from the fetch_places helper method. (#…
Browse files Browse the repository at this point in the history
…4779)

Modifies the fetch_places helper to also get the DissolutionDate and
filter out these dissolved places from the responses

No more Yugoslavia: https://screenshot.googleplex.com/B5axwNbChiP5Y3N

---------

Co-authored-by: Dan Noble <[email protected]>
  • Loading branch information
gmechali and dwnoble authored Dec 10, 2024
1 parent 4342b8f commit 666e4aa
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
18 changes: 15 additions & 3 deletions server/routes/dev_place/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,21 @@ def related_places(place_dcid: str):

# Get place objects for nearby, similar, and child places
all_place_by_dcid = {p.dcid: p for p in all_places}
nearby_places = [all_place_by_dcid[dcid] for dcid in nearby_place_dcids]
similar_places = [all_place_by_dcid[dcid] for dcid in similar_place_dcids]
child_places = [all_place_by_dcid[dcid] for dcid in child_place_dcids]
nearby_places = [
all_place_by_dcid[dcid]
for dcid in nearby_place_dcids
if not all_place_by_dcid[dcid].dissolved
]
similar_places = [
all_place_by_dcid[dcid]
for dcid in similar_place_dcids
if not all_place_by_dcid[dcid].dissolved
]
child_places = [
all_place_by_dcid[dcid]
for dcid in child_place_dcids
if not all_place_by_dcid[dcid].dissolved
]

response = RelatedPlacesApiResponse(childPlaceType=child_place_type,
childPlaces=child_places,
Expand Down
1 change: 1 addition & 0 deletions server/routes/dev_place/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Place:
dcid: str
name: str
types: List[str]
dissolved: bool = False


@dataclass
Expand Down
9 changes: 7 additions & 2 deletions server/routes/dev_place/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def fetch_places(place_dcids: List[str], locale=DEFAULT_LOCALE) -> List[Place]:
Returns:
List[Place]: A list of Place objects with names in the specified locale.
"""
props = ['typeOf', 'name']
props = ['typeOf', 'name', 'dissolutionDate']
# Only fetch names with locale-specific tags if the desired locale is non-english
if locale != DEFAULT_LOCALE:
props.append('nameWithLanguage')
Expand All @@ -247,11 +247,16 @@ def fetch_places(place_dcids: List[str], locale=DEFAULT_LOCALE) -> List[Place]:

place_names = place_props.get('name', [])
default_name = place_names[0] if place_names else place_dcid
dissolved = bool(place_props.get('dissolutionDate'))

place_types = place_props.get('typeOf', [])
# Use the name with locale if available, otherwise fall back to the default ('en') name
name = name_with_locale or default_name
places.append(Place(dcid=place_dcid, name=name, types=place_types))
places.append(
Place(dcid=place_dcid,
name=name,
types=place_types,
dissolved=dissolved))
return places


Expand Down

0 comments on commit 666e4aa

Please sign in to comment.