-
-
Notifications
You must be signed in to change notification settings - Fork 59
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
CB-359: Implemented the reviewal of labels #264
Merged
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
680413d
Changes made to SQL scripts in order to support the reviewal of labels
spellew 2cd202d
Implemented the retrieval of labels through brainzutils
spellew 0558b7c
Implemented the searching of labels
spellew 8bfae4f
Implemented the reviewal of labels
spellew b05cc1c
Fixed testing
spellew 3adc216
Removed comments and unused imports
spellew 4545d92
Updated label entity page to display name, info, reviews, and externa…
spellew 9df5cd6
Removed unused imports
spellew f134e12
Added rating support for labels
spellew 636ce3f
Updated label render_template with proper arguments
spellew aa643e9
Updated label placeholder image
spellew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) | ||
ferbncode marked this conversation as resolved.
Show resolved
Hide resolved
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,13 @@ | |
{{ _('Artist') }} | ||
</span> | ||
{% endif %} | ||
{% elif entity_type == 'label' %} | ||
<img src="{{ get_static_path('images/placeholder_place.svg') }}" {{ attributes }} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
{% if overlay_type %} | ||
<span class="entity-type label"> | ||
{{ _('Label') }} | ||
</span> | ||
{% endif %} | ||
{% else %} {# release-group #} | ||
<img {{ attributes }} /> | ||
{% if overlay_type %} | ||
|
@@ -153,8 +160,10 @@ | |
{% endif %} | ||
{% endmacro %} | ||
|
||
{% macro show_avg_rating(rating, count) %} | ||
<i class="glyphicon glyphicon-star"></i> | ||
{% macro show_avg_rating(rating, count, show_glyphicon=True) %} | ||
{% if show_glyphicon %} | ||
<i class="glyphicon glyphicon-star"></i> | ||
{% endif %} | ||
<span style="font-size: 16px;">{{ rating }}</span><em class="text-muted">/5 {{ _('based on %(number)s ratings', number=count) }}</em> | ||
{% endmacro %} | ||
|
||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw this, this should be in a different script so I can run it on the main db. Generally, each PR should have a single schema change script.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right. @spellew Please add schema change scripts to
admin/schema_changes
(One forartists
and one forlabels
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @paramsingh for pointing that out :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And for fixing it too.