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-270: Implemented the reviewal of recordings #265
Changes from 14 commits
f645530
1f440a8
e4d1bc4
37bd421
9af57f6
adbc6bc
6465ff4
60512c9
00298fe
88332e2
625d03f
d91d5bf
81b7535
7b686ce
5fa2056
1b57962
7e6159f
8fa4fc9
b4ae26b
2b41a34
a3a3bf9
8fd7cf3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TYPE entity_types ADD VALUE 'recording' AFTER 'label'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ CREATE TYPE entity_types AS ENUM ( | |
'event', | ||
'place', | ||
'artist', | ||
'label' | ||
'label', | ||
'recording' | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
"place", | ||
"release_group", | ||
"artist", | ||
"recording", | ||
"label", | ||
] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from brainzutils import cache | ||
from brainzutils.musicbrainz_db.recording import fetch_multiple_recordings | ||
from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION | ||
|
||
|
||
def get_recording_by_id(mbid): | ||
"""Get recording with MusicBrainz ID. | ||
|
||
Args: | ||
mbid (uuid): MBID(gid) of the recording. | ||
Returns: | ||
Dictionary containing the recording information | ||
""" | ||
key = cache.gen_key(mbid) | ||
recording = cache.get(key) | ||
if not recording: | ||
recording = fetch_multiple_recordings( | ||
[mbid], | ||
includes=['artists', 'work-rels', 'url-rels'], | ||
).get(mbid) | ||
recording.update({'length': recording['length'] * 1000.0}) | ||
cache.set(key=key, val=recording, time=DEFAULT_CACHE_EXPIRATION) | ||
return recording |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{% extends 'base.html' %} | ||
{% from 'macros.html' import show_avg_rating, entity_rate_form, show_external_reviews with context %} | ||
|
||
{% block title %} | ||
{{ _('Recording "%(name)s" by %(artist)s', name=recording.name, artist=recording['artist-credit-phrase']) }} | ||
- CritiqueBrainz | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<div class="clearfix"> | ||
<h2 class="pull-left"> | ||
{% set artist = [] %} | ||
{% for credit in recording['artists'] %} | ||
{% if credit.name %} | ||
{% do artist.append('<a href="%s">'|safe % url_for('artist.entity', mbid=credit.id) ~ credit.name ~ '</a>'|safe) %} | ||
{% if credit.join_phrase %} | ||
{% do artist.append(credit.join_phrase) %} | ||
{% endif %} | ||
{% else %} | ||
{% do artist.append(credit) %} | ||
{% endif %} | ||
{% endfor %} | ||
|
||
{{ _('%(recording)s by %(artist)s', recording = recording.name, artist = artist|join()) }} | ||
</h2> | ||
|
||
{% if not my_review %} | ||
<a id="write-review" href="{{ url_for('review.create', recording=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 id="recording-details" class="row"> | ||
<div class="col-md-9"> | ||
{{ entity_rate_form('recording', 'recording') }} | ||
<br/><br/> | ||
<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> | ||
<ul class="pagination"> | ||
{% set pages = count//limit %} | ||
{% if count%limit %} | ||
{% set pages = pages+1 %} | ||
{% endif %} | ||
{% if pages>1 %} | ||
{% for p in range(pages) %} | ||
{% set p_offset = p*limit %} | ||
<li {% if offset == p_offset %}class="active"{% endif %}> | ||
<a href="{{ url_for('recording.entity', id=id, limit=limit, offset=p*limit) }}">{{ p+1 }}</a> | ||
</li> | ||
{% endfor %} | ||
{% endif %} | ||
</ul> | ||
{% endif %} | ||
</div> | ||
|
||
<div class="col-md-3"> | ||
<h4>{{ _('Recording information') }}</h4> | ||
{% if avg_rating %} | ||
<div class="avg-rating"> | ||
{{ show_avg_rating(avg_rating.rating, avg_rating.count) }} | ||
</div> | ||
{% endif %} | ||
{% if external_reviews %} | ||
<b>{{ _('External reviews') }}</b> | ||
<ul class="list-unstyled external-links"> | ||
{{ show_external_reviews(external_reviews) }} | ||
</ul> | ||
{% endif %} | ||
{% if recording['external-urls'] %} | ||
<b>{{ _('External links') }}</b> | ||
<ul class="list-unstyled external-links"> | ||
{% for url in recording['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/recording/{{ recording.id }}"><em>{{ _('Edit on MusicBrainz') }}</em></a> | ||
</div> | ||
</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 %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{% extends 'review/entity/base.html' %} | ||
|
||
{% set recording = review.entity_id | entity_details(type='recording') %} | ||
|
||
{% block title %} | ||
{% set recording_title = recording.name | default(_('[Unknown recording]')) %} | ||
{{ _('Review of "%(recording)s" by %(user)s', recording=recording_title, user=review.user.display_name) }} - CritiqueBrainz | ||
{% endblock %} | ||
|
||
{% block entity_title %} | ||
<h2 id="title"> | ||
{% if recording %} | ||
{% set recording_name = '<a href="%s">' | safe % url_for('recording.entity', id=review.entity_id) ~ recording.name ~ '</a>'|safe %} | ||
{% else %} | ||
{% set recording_name = _('[Unknown recording]') %} | ||
{% endif %} | ||
|
||
{{ _('%(recording)s', recording=recording_name) }} | ||
|
||
{% if recording['life-span'] %} | ||
<small>{{ recording['life-span']['begin'][:4] }}</small> | ||
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. Is this for the year of the recording? Please move this as a function in the template just so that it gets easier to read the code. :) 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. I believe this was accidentally included, since recordings don't have life-spans. |
||
{% endif %} | ||
</h2> | ||
{% endblock %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{% if entity is not defined %} | ||
{% set entity = review.entity_id | entity_details(type=entity_type) %} | ||
{% endif %} | ||
<div class="col-md-12"> | ||
<dl class="dl-horizontal"> | ||
<dt>{{ _('Recording') }}</dt> | ||
<dd> | ||
{{ entity['name'] | default(_('[Unknown recording]')) }} | ||
</dd> | ||
<dt>{{ _('Length') }}</dt> | ||
<dd> | ||
{% if entity['length'] %} | ||
{{ entity['length'] | track_length }} | ||
{% else %} | ||
- | ||
{% endif %} | ||
</dd> | ||
<dt>{{ _('Artist') }}</dt> | ||
<dd> | ||
{{ entity['artist'] or '-' }} | ||
</dd> | ||
{% block more_info %} | ||
{# Information like creation date, votes etc. #} | ||
{% endblock %} | ||
</dl> | ||
</div> |
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.
@spellew Why do you need to multiply by 1000? Also, I see that similar change was made in
work/entity.html
. Could you move both calls to a either a template function or a python function. We should try to stay consistent in order to reduce changes in the future.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.
Brainzutils returns the length in seconds, but we need milliseconds for the track_length function.
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.
Updated here and in the pull request regarding works.