-
-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from spellew/label-entity-support
CB-359: Implemented the reviewal of labels
- Loading branch information
Showing
23 changed files
with
440 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
ALTER TYPE entity_types ADD VALUE 'artist' AFTER 'place'; | ||
ALTER TYPE entity_types ADD VALUE 'label' AFTER 'artist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ CREATE TYPE entity_types AS ENUM ( | |
'release_group', | ||
'event', | ||
'place', | ||
'artist' | ||
'artist', | ||
'label' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"place", | ||
"release_group", | ||
"artist", | ||
"label", | ||
] | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from brainzutils import cache | ||
from brainzutils.musicbrainz_db.label import fetch_multiple_labels | ||
from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION | ||
from critiquebrainz.frontend.external.relationships import label as label_rel | ||
|
||
|
||
def get_label_by_id(mbid): | ||
"""Get label with MusicBrainz ID. | ||
Args: | ||
mbid (uuid): MBID(gid) of the label. | ||
Returns: | ||
Dictionary containing the label information | ||
""" | ||
key = cache.gen_key(mbid) | ||
label = cache.get(key) | ||
if not label: | ||
label = fetch_multiple_labels( | ||
[mbid], | ||
includes=['artist-rels', 'url-rels'], | ||
).get(mbid) | ||
cache.set(key=key, val=label, time=DEFAULT_CACHE_EXPIRATION) | ||
return label_rel.process(label) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
""" | ||
Relationship processor for label entity. | ||
""" | ||
import urllib.parse | ||
from flask_babel import lazy_gettext | ||
|
||
|
||
def process(label): | ||
"""Handles processing supported relation lists.""" | ||
if 'url-rels' in label and label['url-rels']: | ||
label['external-urls'] = _url(label['url-rels']) | ||
return label | ||
|
||
|
||
def _url(url_list): | ||
"""Processor for Label-URL relationship.""" | ||
basic_types = { | ||
'wikidata': {'name': lazy_gettext('Wikidata'), 'icon': 'wikidata-16.png', }, | ||
'discogs': {'name': lazy_gettext('Discogs'), 'icon': 'discogs-16.png', }, | ||
'allmusic': {'name': lazy_gettext('Allmusic'), 'icon': 'allmusic-16.png', }, | ||
'bandcamp': {'name': lazy_gettext('Bandcamp'), 'icon': 'bandcamp-16.png', }, | ||
'official homepage': {'name': lazy_gettext('Official homepage'), 'icon': 'home-16.png', }, | ||
'BBC Music page': {'name': lazy_gettext('BBC Music'), }, | ||
} | ||
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()))) | ||
else: | ||
try: | ||
target = urllib.parse.urlparse(relation['target']) | ||
if relation['type'] == 'lyrics': | ||
external_urls.append(dict( | ||
relation.items() + { | ||
'name': lazy_gettext('Lyrics'), | ||
'disambiguation': target.netloc, | ||
}.items())) | ||
elif relation['type'] == 'wikipedia': | ||
external_urls.append(dict( | ||
relation.items() + { | ||
'name': lazy_gettext('Wikipedia'), | ||
'disambiguation': ( | ||
target.netloc.split('.')[0] + | ||
':' + | ||
urllib.parse.unquote(target.path.split('/')[2]).decode('utf8').replace("_", " ") | ||
), | ||
'icon': 'wikipedia-16.png', | ||
}.items())) | ||
elif relation['type'] == 'youtube': | ||
path = target.path.split('/') | ||
if path[1] == 'user' or path[1] == 'channel': | ||
disambiguation = path[2] | ||
else: | ||
disambiguation = path[1] | ||
external_urls.append(dict( | ||
relation.items() + { | ||
'name': lazy_gettext('YouTube'), | ||
'disambiguation': disambiguation, | ||
'icon': 'youtube-16.png', | ||
}.items())) | ||
elif relation['type'] == 'social network': | ||
if target.netloc == 'twitter.com': | ||
external_urls.append(dict( | ||
relation.items() + { | ||
'name': lazy_gettext('Twitter'), | ||
'disambiguation': target.path.split('/')[1], | ||
'icon': 'twitter-16.png', | ||
}.items())) | ||
else: | ||
# TODO(roman): Process other types here | ||
pass | ||
except Exception: # FIXME(roman): Too broad exception clause. | ||
# TODO(roman): Log error. | ||
pass | ||
|
||
return sorted(external_urls, key=lambda k: k['name']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
{% extends 'base.html' %} | ||
{% from 'macros.html' import entity_rate_form, show_avg_rating with context %} | ||
|
||
{% block title %}{{ label.name }} - CritiqueBrainz{% endblock %} | ||
|
||
{% block content %} | ||
<div class="clearfix"> | ||
<h2 class="pull-left"> | ||
{{ label.name }} | ||
{% if label.disambiguation %} | ||
<small>({{ label.disambiguation }})</small> | ||
{% endif %} | ||
</h2> | ||
|
||
{% if not my_review %} | ||
<a id="write-review" href="{{ url_for('review.create', label=id) }}" | ||
role="button" class="btn btn-success pull-right"> | ||
<span class="glyphicon glyphicon-asterisk"></span> {{ _('Write a review') }} | ||
</a> | ||
{% else %} | ||
<a id="edit-review" href="{{ url_for('review.edit', id=my_review.id) }}" | ||
role="button" class="btn btn-primary pull-right"> | ||
<span class="glyphicon glyphicon-edit"></span> {{ _('Edit my review') }} | ||
</a> | ||
{% endif %} | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-9"> | ||
<h4 style="margin-bottom:0;">{{ _('Reviews') }}</h4> | ||
{% if not reviews %} | ||
<p class="lead" style="text-align: center;">{{ _('No reviews found') }}</p> | ||
{% else %} | ||
<table class="table table-condensed table-hover"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>{{ _('Published on') }}</th> | ||
<th>{{ _('Votes (+/-)') }}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for review in reviews %} | ||
<tr data-review-id="{{ review.id }}"> | ||
<td> | ||
<a href="{{ url_for('review.entity', id=review.id) }}"> | ||
{{ _('by %(reviewer)s', reviewer='<img class="avatar" src="%s&s=16" /> '|safe % review.user.avatar + review.user.display_name) }} | ||
</a> | ||
</td> | ||
<td>{{ review.published_on | date }}</td> | ||
<td>{{ review.votes_positive_count }}/{{ review.votes_negative_count }}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
<div class="col-md-12"> | ||
<ul class="pager"> | ||
{% if not reviews_limit %} | ||
<li class="next"><a href="{{ url_for('label.entity', id=id) }}">{{ _('Hide reviews') }}</a></li> | ||
{% elif reviews_count > reviews_limit %} | ||
<li class="next"><a href="{{ url_for('label.entity', id=id, reviews='all') }}">{{ _('Show all reviews') }}</a></li> | ||
{% endif %} | ||
</ul> | ||
</div> | ||
{% endif %} | ||
<ul class="pagination"></ul> | ||
</div> | ||
|
||
<div class="col-sm-3"> | ||
<h4>{{ _('Label information') }}</h4> | ||
{% if label.type %}<p class="text-muted">{{ label.type }}</p>{% endif %} | ||
|
||
{% if label['external-urls'] %} | ||
<b>{{ _('External links') }}</b> | ||
<ul class="list-unstyled external-links"> | ||
{% for url in label['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> | ||
{% if url.disambiguation %}<span class="text-muted">({{ url.disambiguation }})</span>{% endif %} | ||
</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/label/{{ label.id }}"><em>{{ _('Edit on MusicBrainz') }}</em></a> | ||
</div> | ||
|
||
<br/><br/> | ||
{{ entity_rate_form('label', 'label') }} | ||
{% if avg_rating %} | ||
<div class="avg-rating"> | ||
{{ show_avg_rating(avg_rating.rating, avg_rating.count, show_glyphicon = false) }} | ||
</div> | ||
{% endif %} | ||
</div> | ||
</div> | ||
{% endblock %} | ||
|
||
{% block scripts %} | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/simplemde/latest/simplemde.min.css"/> | ||
<script> | ||
$(document).ready(function() { | ||
$("#ratestars").click(function(e){ | ||
// only submit rating form when user clicks on <i></i> tag (see generated HTML for rating stars on this page) | ||
if (e.target.tagName === 'I') { | ||
$("#rating-form").submit(); | ||
} | ||
}); | ||
}); | ||
</script> | ||
<script src="{{ get_static_path('rating.js') }}"></script> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.