Skip to content

Commit

Permalink
CB-260: Show external URLs and related places on place pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ferbncode authored and gentlecat committed Jul 10, 2017
1 parent 8698fc7 commit 844b197
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion critiquebrainz/frontend/external/musicbrainz_db/place.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions
from critiquebrainz.frontend.external.musicbrainz_db.serialize import to_dict_places
from critiquebrainz.frontend.external.musicbrainz_db.helpers import entity_relation_helper
from critiquebrainz.frontend.external.relationships import place as place_rel
from brainzutils import cache


Expand All @@ -27,7 +28,7 @@ def get_place_by_id(mbid):
mbid, includes=['artist-rels', 'place-rels', 'release-group-rels', 'url-rels'],
)
cache.set(key=key, val=place, time=DEFAULT_CACHE_EXPIRATION)
return place
return place_rel.process(place)


def _get_place_by_id(place_id, includes=[]):
Expand Down
44 changes: 44 additions & 0 deletions critiquebrainz/frontend/external/relationships/place.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from flask_babel import lazy_gettext


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'])
return place


def _url(url_list):
"""Processor for Place-URL relationship."""
basic_types = {
'wikidata': {
'name': lazy_gettext('Wikidata'), 'icon': 'wikidata-16.png',
},
'discogs': {
'name': lazy_gettext('Discogs'), 'icon': 'discogs-16.png',
},
'last.fm': {
'name': lazy_gettext('Last.fm'), 'icon': 'lastfm-16.png',
},
'official homepage': {
'name': lazy_gettext('Official homepage'), 'icon': 'home-16.png',
},
}
external_urls = []
for relation in url_list:
if relation['type'] in basic_types:
external_urls.append(dict(list(relation.items()) + list(basic_types[relation['type']].items())))
return sorted(external_urls, key=lambda k: k['name'])


def _place(place_list):
"""Processor for Place-Place relationship."""
related_places = []
for relation in place_list:
if relation['direction'] == 'backward':
related_places.append(relation)
return related_places
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions critiquebrainz/frontend/templates/place/entity.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,35 @@ <h4 style="margin-bottom:0;">{{ _('Reviews') }}</h4>

<div class="col-md-3">
<h4>{{ _('Place information') }}</h4>
{% if place['external-urls'] %}
<b>{{ _('External links') }}</b>
<ul class="list-unstyled external-links">
{% for url in place['external-urls'] %}
<li class="clearfix">
<div class="favicon-container">
{% if url.icon %}
<img src="{{ get_static_path('favicons/'+url.icon) }}" />
{% else %}
<img src="{{ get_static_path('favicons/external-16.png') }}" />
{% endif %}
</div>
<a href="{{ url.url.url }}">{{ url.name }}</a>
</li>
{% endfor %}
</ul>
{% endif %}

{% if place['place-rels'] %}
<b>{{ _('Part of') }}</b>
<ul class="list-unstyled">
{% for relation in place['place-rels'] %}
<li class="clearfix">
<a href="{{ url_for('place.entity', id=relation['place']['id']) }}">{{ 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>
<a href="https://musicbrainz.org/place/{{ place.id }}"><em>{{ _('Edit on MusicBrainz') }}</em></a>
Expand Down

0 comments on commit 844b197

Please sign in to comment.