Skip to content

Commit

Permalink
update to portal_utils/get_identifying_path
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed May 28, 2024
1 parent d9bab89 commit 174a83f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ def get_schema_subtype_names(self, type_name: str) -> List[str]:

@function_cache(maxsize=100, serialize_key=True)
def get_identifying_paths(self, portal_object: dict, portal_type: Optional[Union[str, dict]] = None,
first_only: bool = False,
lookup_strategy: Optional[Union[Callable, bool]] = None) -> List[str]:
"""
Returns the list of the identifying Portal (URL) paths for the given Portal object. Favors any uuid
Expand Down Expand Up @@ -467,7 +468,10 @@ def is_lookup_subtypes(lookup_options: int) -> bool: # noqa
# And note the disction of just using /{uuid} here rather than /{type}/{uuid} as in the else
# statement below is not really necessary; just here for emphasis that this is all that's needed.
#
results.append(f"/{identifying_value}")
if first_only is True:
results.append(f"/{portal_type}/{identifying_value}")
else:
results.append(f"/{identifying_value}")
elif isinstance(identifying_value, list):
for identifying_value_item in identifying_value:
if identifying_value_item:
Expand Down Expand Up @@ -497,12 +501,15 @@ def is_lookup_subtypes(lookup_options: int) -> bool: # noqa
if is_lookup_subtypes(lookup_options):
for subtype_name in self.get_schema_subtype_names(portal_type):
results.append(f"/{subtype_name}/{identifying_value}")
if (first_only is True) and results:
return results
return results

@function_cache(maxsize=100, serialize_key=True)
def get_identifying_path(self, portal_object: dict, portal_type: Optional[Union[str, dict]] = None,
lookup_strategy: Optional[Union[Callable, bool]] = None) -> Optional[str]:
if identifying_paths := self.get_identifying_paths(portal_object, portal_type, lookup_strategy):
if identifying_paths := self.get_identifying_paths(portal_object, portal_type, first_only=True,
lookup_strategy=lookup_strategy):
return identifying_paths[0]
return None

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.8.6.1b10"
version = "8.8.6.1b11"
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 174a83f

Please sign in to comment.