Skip to content

Commit

Permalink
Add twitter and relations highlight pages (#552)
Browse files Browse the repository at this point in the history
* Add highlights

* Update and add routes

* Update ui.py
  • Loading branch information
cthoyt authored Sep 3, 2022
1 parent 166b675 commit bf3e715
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
38 changes: 38 additions & 0 deletions src/bioregistry/app/templates/highlights/relations.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}
{% import "macros.html" as utils %}

{% block title %}{{ config.METAREGISTRY_TITLE }} - Relations{% endblock %}

{% macro render_dict(ddd) -%}
<dl class="row">
{% for k, v in ddd.items() %}
<dt class="col-3" style="text-align: right">{{ k }}
{% if k not in manager.registry %}
<i class="far fa-question-circle" style="color: red;"></i>
{% endif %}
</dt>
<dd class="col-9">
{% for prefix in v %}
{{ utils.render_prefix(prefix, classes="badge badge-pill badge-primary") }}
{% endfor %}
</dd>
{% endfor %}
</dl>
{% endmacro %}

{% block container %}
<div class="card">
<div class="card-header">
Relations
</div>
<div class="card-body">
<p>This page provides an overview on canonical/part of/provides relationships</p>
<h3>Canonical</h3>
{{ render_dict(manager.canonical_for) }}
<h3>Provided By</h3>
{{ render_dict(manager.provided_by) }}
<h3>Has Parts</h3>
{{ render_dict(manager.has_parts) }}
</div>
</div>
{% endblock %}
28 changes: 28 additions & 0 deletions src/bioregistry/app/templates/highlights/twitter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{% extends "base.html" %}
{% import "macros.html" as utils %}

{% block title %}{{ config.METAREGISTRY_TITLE }} - Twitter{% endblock %}

{% block container %}
<div class="card">
<div class="card-header">
Twitter
</div>
<table class="table">
<thead></thead>
<tbody>
{% for handle, resources in twitters.items() %}
<tr>
<td><a href="https://twitter.com/{{ handle }}">@{{ handle }}</a></td>
<td>
{% for resource in resources %}
{{ utils.render_prefix(resource.prefix, classes="badge badge-pill badge-primary") }}
{% endfor %}
</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>
{% endblock %}
4 changes: 2 additions & 2 deletions src/bioregistry/app/templates/macros.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<code>{{ curie_to_str(prefix, identifier) }}</code>
{% endmacro %}

{% macro render_prefix(prefix) -%}
<a href="{{ url_for("metaregistry_ui.resource", prefix=prefix) }}">
{% macro render_prefix(prefix, classes="") -%}
<a class="{{ classes }}" href="{{ url_for("metaregistry_ui.resource", prefix=prefix) }}">
<code>{{ prefix }}</code>
</a>
{% endmacro %}
Expand Down
18 changes: 18 additions & 0 deletions src/bioregistry/app/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import datetime
import itertools as itt
import platform
from collections import defaultdict
from operator import attrgetter
from pathlib import Path
from typing import Optional
Expand Down Expand Up @@ -509,3 +510,20 @@ def schema():
def json_schema():
"""Return the JSON schema."""
return jsonify(get_json_schema())


@ui_blueprint.route("/highlights/twitter")
def highlights_twitter():
"""Render the twitter highlights page."""
twitters = defaultdict(list)
for resource in manager.registry.values():
twitter = resource.get_twitter()
if twitter:
twitters[twitter].append(resource)
return render_template("highlights/twitter.html", twitters=twitters)


@ui_blueprint.route("/highlights/relations")
def highlights_relations():
"""Render the relations highlights page."""
return render_template("highlights/relations.html")

0 comments on commit bf3e715

Please sign in to comment.