Skip to content

Commit

Permalink
Merge pull request #430 from metabrainz/place-part-of-parts
Browse files Browse the repository at this point in the history
Show both forward and backward place-place rels (Parts and Part of)
  • Loading branch information
alastair authored May 31, 2022
2 parents 1dd3da7 + 56125d5 commit 267052b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 12 additions & 8 deletions critiquebrainz/frontend/external/relationships/place.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
from flask_babel import lazy_gettext


PLACE_PLACE_PARTS_REL_ID = 'ff683f48-eff1-40ab-a58f-b128098ffe92'


def process(place):
"""Handles processing supported relation lists."""

if 'url-rels' in place and place['url-rels']:
place['external-urls'] = _url(place['url-rels'])

if 'place-rels' in place and place['place-rels']:
place['place-rels'] = _place(place['place-rels'])
place_rels = place.pop('place-rels', [])
parts = _place_place_rels(place_rels, PLACE_PLACE_PARTS_REL_ID, 'forward')
part_of = _place_place_rels(place_rels, PLACE_PLACE_PARTS_REL_ID, 'backward')
if parts:
place['parts'] = parts
if part_of:
place['part-of'] = part_of
return place


Expand All @@ -35,10 +43,6 @@ def _url(url_list):
return sorted(external_urls, key=lambda k: k['name'])


def _place(place_list):
def _place_place_rels(place_list, rel_type, rel_direction):
"""Processor for Place-Place relationship."""
related_places = []
for relation in place_list:
if relation['direction'] == 'backward':
related_places.append(relation)
return related_places
return [relation for relation in place_list if relation['direction'] == rel_direction and relation['type-id'] == rel_type]
14 changes: 12 additions & 2 deletions critiquebrainz/frontend/templates/place/entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,26 @@ <h4>{{ _('Place information') }}</h4>
</ul>
{% endif %}

{% if place['place-rels'] is defined %}
{% if place['part-of'] is defined %}
<b>{{ _('Part of') }}</b>
<ul class="list-unstyled">
{% for relation in place['place-rels'] %}
{% for relation in place['part-of'] %}
<li class="clearfix">
<a href="{{ url_for('place.entity', id=relation['place'].mbid) }}">{{ relation['place']['name'] }}</a>
</li>
{% endfor %}
</ul>
{% endif %}
{% if place['parts'] is defined %}
<b>{{ _('Parts') }}</b>
<ul class="list-unstyled">
{% for relation in place['parts'] %}
<li class="clearfix">
<a href="{{ url_for('place.entity', id=relation['place'].mbid) }}">{{ relation['place']['name'] }}</a>
</li>
{% endfor %}
</ul>
{% endif %}

<div class="external-links">
<div class="favicon-container"><img src="{{ get_static_path('favicons/musicbrainz-16.svg') }}" /></div>
Expand Down

0 comments on commit 267052b

Please sign in to comment.