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

Show provenance for annotations in web app #1095

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions src/bioregistry/app/templates/resource.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<div class="col-8">
<h5 style="margin: 0"><a href="{{ url_for("metaregistry_ui.resources") }}">Registry</a> <i
class="fas fa-angle-right"></i> {{ name }}
<span type="button" class="btn btn-secondary" data-toggle="tooltip" data-placement="top" title="This name annotation comes from {{ name_source_name }} and is redistributed under the {{ name_source_license }}.">
<i class="fas fa-book"></i>
</span>
{{ utils.render_resource_warnings(resource) }}
</h5>
</div>
Expand Down
8 changes: 7 additions & 1 deletion src/bioregistry/app/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,19 @@ def resource(prefix: str):
example_curie_extras = [
_resource.get_curie(example_extra, use_preferred=True) for example_extra in example_extras
]
name, name_source_metaprefix = _resource.get_name(provenance=True)
name_source_name = manager.get_registry(name_source_metaprefix).name
name_source_license = manager.get_registry(name_source_metaprefix).license
return render_template(
"resource.html",
zip=zip,
prefix=prefix,
resource=_resource,
bioschemas=json.dumps(_resource.get_bioschemas_jsonld(), ensure_ascii=False),
name=manager.get_name(prefix),
name=name,
name_source_metaprefix=name_source_metaprefix,
name_source_name=name_source_name,
name_source_license=name_source_license,
example=example,
example_extras=example_extras,
example_curie=example_curie,
Expand Down
13 changes: 10 additions & 3 deletions src/bioregistry/schema/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,12 @@ def get_mapped_prefix(self, metaprefix: str) -> Optional[str]:
return None
return self.get_mappings().get(metaprefix)

def get_prefix_key(self, key: str, metaprefixes: Union[str, Sequence[str]]):
def get_prefix_key(self, key: str, metaprefixes: Union[str, Sequence[str]], *, provenance: bool = False):
"""Get a key enriched by the given external resources' data."""
rv = self.dict().get(key)
if rv is not None:
if provenance:
return rv, "bioregistry"
return rv
if isinstance(metaprefixes, str):
metaprefixes = [metaprefixes]
Expand All @@ -678,7 +680,11 @@ def get_prefix_key(self, key: str, metaprefixes: Union[str, Sequence[str]]):
raise TypeError
rv = external.get(key)
if rv is not None:
if provenance:
return rv, metaprefix
return rv
if provenance:
return None, None
return None

def get_default_uri(self, identifier: str) -> Optional[str]:
Expand Down Expand Up @@ -832,8 +838,8 @@ def get_mappings(self) -> Dict[str, str]:
"""Get the mappings to external registries, if available."""
return self.mappings or {}

def get_name(self) -> Optional[str]:
"""Get the name for the given prefix, it it's available."""
def get_name(self, *, provenance: bool = False) -> Optional[str]:
"""Get the name for the given prefix, if it's available."""
return self.get_prefix_key(
"name",
(
Expand All @@ -856,6 +862,7 @@ def get_name(self) -> Optional[str]:
"bartoc",
"lov",
),
provenance=provenance
)

def get_description(self, use_markdown: bool = False) -> Optional[str]:
Expand Down
Loading