From 2c1a5d97b04e9a29867a0627abc50828756f9cb2 Mon Sep 17 00:00:00 2001 From: spellew Date: Sun, 16 Jun 2019 13:15:04 -0400 Subject: [PATCH 01/28] Changes made to SQL scripts in order to support the reviewal of recordings --- admin/schema_changes/16.sql | 1 + admin/sql/create_types.sql | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/admin/schema_changes/16.sql b/admin/schema_changes/16.sql index b1f4e5377..fd697495f 100644 --- a/admin/schema_changes/16.sql +++ b/admin/schema_changes/16.sql @@ -1 +1,2 @@ ALTER TYPE entity_types ADD VALUE 'artist' AFTER 'place'; +ALTER TYPE entity_types ADD VALUE 'recording' AFTER 'artist'; diff --git a/admin/sql/create_types.sql b/admin/sql/create_types.sql index 27a364f85..5c2dde6c0 100644 --- a/admin/sql/create_types.sql +++ b/admin/sql/create_types.sql @@ -11,5 +11,6 @@ CREATE TYPE entity_types AS ENUM ( 'place', 'work', 'artist', - 'label' + 'label', + 'recording' ); From 9144cd55540340a9ba703fa71b57b7575407f0c1 Mon Sep 17 00:00:00 2001 From: spellew Date: Sun, 16 Jun 2019 13:23:01 -0400 Subject: [PATCH 02/28] Implemented the retrieval of recordings through brainzutils --- .idea/.gitignore | 8 +++++ .idea/critiquebrainz.iml | 34 +++++++++++++++++++ .idea/inspectionProfiles/Project_Default.xml | 16 +++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ .../external/musicbrainz_db/entities.py | 8 +++++ .../external/musicbrainz_db/recording.py | 22 ++++++++++++ 9 files changed, 112 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/critiquebrainz.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 critiquebrainz/frontend/external/musicbrainz_db/recording.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 000000000..73f69e095 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/critiquebrainz.iml b/.idea/critiquebrainz.iml new file mode 100644 index 000000000..98bacd12c --- /dev/null +++ b/.idea/critiquebrainz.iml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 000000000..6a5e1293b --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,16 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 000000000..105ce2da2 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 000000000..9640ff02d --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 000000000..e08c0bf70 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 000000000..94a25f7f4 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/critiquebrainz/frontend/external/musicbrainz_db/entities.py b/critiquebrainz/frontend/external/musicbrainz_db/entities.py index 8453c74f9..852e026fb 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/entities.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/entities.py @@ -4,6 +4,7 @@ from brainzutils.musicbrainz_db.place import fetch_multiple_places from brainzutils.musicbrainz_db.release_group import fetch_multiple_release_groups from brainzutils.musicbrainz_db.work import fetch_multiple_works +from brainzutils.musicbrainz_db.recording import fetch_multiple_recordings from critiquebrainz.frontend.external.musicbrainz_db.artist import get_artist_by_id from critiquebrainz.frontend.external.musicbrainz_db.event import get_event_by_id @@ -11,6 +12,7 @@ from critiquebrainz.frontend.external.musicbrainz_db.place import get_place_by_id from critiquebrainz.frontend.external.musicbrainz_db.release_group import get_release_group_by_id from critiquebrainz.frontend.external.musicbrainz_db.work import get_work_by_id +from critiquebrainz.frontend.external.musicbrainz_db.recording import get_recording_by_id def get_multiple_entities(entities): @@ -32,6 +34,7 @@ def get_multiple_entities(entities): release_group_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'release_group', entities)] artist_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'artist', entities)] label_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'label', entities)] + recording_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'recording', entities)] place_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'place', entities)] event_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'event', entities)] work_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'work', entities)] @@ -57,6 +60,9 @@ def get_multiple_entities(entities): entities_info.update(fetch_multiple_works( work_mbids, )) + entities_info.update(fetch_multiple_recordings( + recording_mbids, + )) return entities_info @@ -74,4 +80,6 @@ def get_entity_by_id(id, type='release_group'): entity = get_event_by_id(str(id)) elif type == 'work': entity = get_work_by_id(str(id)) + elif type == 'recording': + entity = get_recording_by_id(str(id)) return entity diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py new file mode 100644 index 000000000..4b33f0f6e --- /dev/null +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -0,0 +1,22 @@ +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=['artist-rels', 'work-rels', 'url-rels'], + ).get(mbid) + cache.set(key=key, val=recording, time=DEFAULT_CACHE_EXPIRATION) + return recording From 72687004498a816cdf78b04dcd44437ef2658ead Mon Sep 17 00:00:00 2001 From: spellew Date: Sun, 16 Jun 2019 13:35:11 -0400 Subject: [PATCH 03/28] Implemented the searching of recordings --- critiquebrainz/frontend/__init__.py | 2 + .../frontend/external/musicbrainz.py | 6 +++ critiquebrainz/frontend/templates/navbar.html | 1 + .../frontend/templates/recording/entity.html | 1 + .../templates/release_group/entity.html | 2 +- .../frontend/templates/search/index.html | 8 ++++ .../frontend/templates/search/results.html | 24 +++++++++++ .../frontend/templates/search/selector.html | 31 ++++++++++++++ .../templates/search/selector_results.html | 30 ++++++++++++++ critiquebrainz/frontend/views/recording.py | 41 +++++++++++++++++++ critiquebrainz/frontend/views/search.py | 10 ++++- 11 files changed, 154 insertions(+), 2 deletions(-) create mode 100644 critiquebrainz/frontend/templates/recording/entity.html create mode 100644 critiquebrainz/frontend/views/recording.py diff --git a/critiquebrainz/frontend/__init__.py b/critiquebrainz/frontend/__init__.py index a78804efb..ef3d386d1 100644 --- a/critiquebrainz/frontend/__init__.py +++ b/critiquebrainz/frontend/__init__.py @@ -138,6 +138,7 @@ def create_app(debug=None, config_path=None): from critiquebrainz.frontend.views.release_group import release_group_bp from critiquebrainz.frontend.views.release import release_bp from critiquebrainz.frontend.views.work import work_bp + from critiquebrainz.frontend.views.recording import recording_bp from critiquebrainz.frontend.views.event import event_bp from critiquebrainz.frontend.views.mapping import mapping_bp from critiquebrainz.frontend.views.user import user_bp @@ -161,6 +162,7 @@ def create_app(debug=None, config_path=None): app.register_blueprint(release_group_bp, url_prefix='/release-group') app.register_blueprint(release_bp, url_prefix='/release') app.register_blueprint(work_bp, url_prefix='/work') + app.register_blueprint(recording_bp, url_prefix='/recording') app.register_blueprint(event_bp, url_prefix='/event') app.register_blueprint(place_bp, url_prefix='/place') app.register_blueprint(mapping_bp, url_prefix='/mapping') diff --git a/critiquebrainz/frontend/external/musicbrainz.py b/critiquebrainz/frontend/external/musicbrainz.py index a3c625cd4..ec8222aa9 100644 --- a/critiquebrainz/frontend/external/musicbrainz.py +++ b/critiquebrainz/frontend/external/musicbrainz.py @@ -55,3 +55,9 @@ def search_labels(query='', limit=None, offset=None): """Search for labels.""" api_resp = musicbrainzngs.search_labels(query=query, limit=limit, offset=offset) return api_resp.get('label-count'), api_resp.get('label-list') + + +def search_recordings(query='', limit=None, offset=None): + """Search for recordings.""" + api_resp = musicbrainzngs.search_recordings(query=query, limit=limit, offset=offset) + return api_resp.get('recording-count'), api_resp.get('recording-list') diff --git a/critiquebrainz/frontend/templates/navbar.html b/critiquebrainz/frontend/templates/navbar.html index b2e25b632..77e597904 100644 --- a/critiquebrainz/frontend/templates/navbar.html +++ b/critiquebrainz/frontend/templates/navbar.html @@ -100,6 +100,7 @@ + diff --git a/critiquebrainz/frontend/templates/recording/entity.html b/critiquebrainz/frontend/templates/recording/entity.html new file mode 100644 index 000000000..21f5da261 --- /dev/null +++ b/critiquebrainz/frontend/templates/recording/entity.html @@ -0,0 +1 @@ +{% extends 'base.html' %} diff --git a/critiquebrainz/frontend/templates/release_group/entity.html b/critiquebrainz/frontend/templates/release_group/entity.html index 49cc7f1e7..96ebaa3c7 100644 --- a/critiquebrainz/frontend/templates/release_group/entity.html +++ b/critiquebrainz/frontend/templates/release_group/entity.html @@ -113,7 +113,7 @@

{{ _('Tracklist') }}

{{ track.number }} - + {{ track.recording_title }} diff --git a/critiquebrainz/frontend/templates/search/index.html b/critiquebrainz/frontend/templates/search/index.html index 08675df77..8d0969068 100644 --- a/critiquebrainz/frontend/templates/search/index.html +++ b/critiquebrainz/frontend/templates/search/index.html @@ -24,6 +24,7 @@

{{ _('Search') }}

+
+ +
+
+ +
+
+ + + + + @@ -157,6 +180,7 @@

{{ _('Label selection') }}

or request.args.get('place', default=False) or request.args.get('work', default=False) or request.args.get('label', default=False) + or request.args.get('recording', default=False) %}
{% if not results %} @@ -209,6 +233,13 @@

{{ _('Label selection') }}

{{ _('Language') }} + {% elif type=="recording" %} + + {{ _('Title') }} + {{ _('Length') }} + {{ _('Artist') }} + {{ _('Release group') }} + {% endif %} {% include 'search/selector_results.html' %} diff --git a/critiquebrainz/frontend/templates/search/selector_results.html b/critiquebrainz/frontend/templates/search/selector_results.html index 61dac6819..ad306eb6a 100644 --- a/critiquebrainz/frontend/templates/search/selector_results.html +++ b/critiquebrainz/frontend/templates/search/selector_results.html @@ -131,6 +131,36 @@ + + + + +{% elif type=="recording" %} + + + {{ result['name'] }} + + + {% if result['length'] %} + {{ result['length'] | track_length }} + {% else %} + - + {% endif %} + + + {{ result['artist-credit'][0]['artist']['name'] or '-' }} + + + {% if result['release-list'] %} + + {{ result['release-list'][0].title or '-' }} + + {% else %} + - + {% endif %} + + + diff --git a/critiquebrainz/frontend/views/recording.py b/critiquebrainz/frontend/views/recording.py new file mode 100644 index 000000000..126963fec --- /dev/null +++ b/critiquebrainz/frontend/views/recording.py @@ -0,0 +1,41 @@ +# critiquebrainz - Repository for Creative Commons licensed reviews +# +# Copyright (C) 2018 MetaBrainz Foundation Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +from flask import Blueprint, render_template, request +from flask_login import current_user +from flask_babel import gettext +from werkzeug.exceptions import NotFound +import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording +import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions +import critiquebrainz.db.review as db_review +from critiquebrainz.frontend.forms.rate import RatingEditForm +from critiquebrainz.frontend.views import get_avg_rating + + +recording_bp = Blueprint('recording', __name__) + + +@recording_bp.route('/') +def entity(id): + id = str(id) + try: + recording = mb_recording.get_recording_by_id(id) + except mb_exceptions.NoDataFoundException: + raise NotFound(gettext("Sorry, we couldn't find a release group with that MusicBrainz ID.")) + + return render_template('recording/entity.html', id=recording['id'], recording=recording) diff --git a/critiquebrainz/frontend/views/search.py b/critiquebrainz/frontend/views/search.py index ae31e1464..b352ed492 100644 --- a/critiquebrainz/frontend/views/search.py +++ b/critiquebrainz/frontend/views/search.py @@ -21,6 +21,8 @@ def search_wrapper(query, type, offset=None): count, results = musicbrainz.search_works(query, limit=RESULTS_LIMIT, offset=offset) elif type == "label": count, results = musicbrainz.search_labels(query, limit=RESULTS_LIMIT, offset=offset) + elif type == "recording": + count, results = musicbrainz.search_recordings(query, limit=RESULTS_LIMIT, offset=offset) else: count, results = 0, [] else: @@ -52,6 +54,7 @@ def more(): def selector(): release_group = request.args.get('release_group') artist = request.args.get('artist') + recording = request.args.get('recording') label = request.args.get('label') event = request.args.get('event') place = request.args.get('place') @@ -68,6 +71,8 @@ def selector(): count, results = musicbrainz.search_labels(label, limit=RESULTS_LIMIT) elif work: count, results = musicbrainz.search_works(work, limit=RESULTS_LIMIT) + elif recording: + count, results = musicbrainz.search_recordings(recording, limit=RESULTS_LIMIT) elif event: count, results = musicbrainz.search_events(event, limit=RESULTS_LIMIT) elif place: @@ -77,12 +82,13 @@ def selector(): return render_template('search/selector.html', next=next, type=type, results=results, count=count, limit=RESULTS_LIMIT, artist=artist, release_group=release_group, event=event, - work=work, place=place, label=label) + work=work, place=place, label=label, recording=recording) @search_bp.route('/selector/more') def selector_more(): artist = request.args.get('artist') + recording = request.args.get('recording') release_group = request.args.get('release_group') label = request.args.get('label') event = request.args.get('event') @@ -100,6 +106,8 @@ def selector_more(): count, results = musicbrainz.search_artists(artist, limit=RESULTS_LIMIT, offset=offset) elif type == 'label': count, results = musicbrainz.search_labels(label, limit=RESULTS_LIMIT, offset=offset) + elif type == 'recording': + count, results = musicbrainz.search_recordings(recording, limit=RESULTS_LIMIT, offset=offset) elif type == 'event': count, results = musicbrainz.search_events(event, limit=RESULTS_LIMIT, offset=offset) elif type == 'place': From 5e19e3cf42d3142d707bb726c1a27a67c24d6ac4 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Tue, 29 Dec 2020 14:59:14 +0530 Subject: [PATCH 04/28] Fixup --- .idea/.gitignore | 8 ----- .idea/critiquebrainz.iml | 34 ------------------- .idea/inspectionProfiles/Project_Default.xml | 16 --------- .../inspectionProfiles/profiles_settings.xml | 6 ---- .idea/misc.xml | 4 --- .idea/modules.xml | 8 ----- .idea/vcs.xml | 6 ---- 7 files changed, 82 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/critiquebrainz.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e095..000000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.idea/critiquebrainz.iml b/.idea/critiquebrainz.iml deleted file mode 100644 index 98bacd12c..000000000 --- a/.idea/critiquebrainz.iml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 6a5e1293b..000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 105ce2da2..000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 9640ff02d..000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index e08c0bf70..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f4..000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From fc27360fa6c0e3987ebcad5c49a3e5e579a26534 Mon Sep 17 00:00:00 2001 From: spellew Date: Sun, 16 Jun 2019 13:43:52 -0400 Subject: [PATCH 05/28] Implemented the reviewal of recordings --- critiquebrainz/db/review.py | 1 + .../external/musicbrainz_db/recording.py | 5 ++-- .../frontend/static/styles/main.less | 7 +++++ .../frontend/templates/entity_review.html | 2 ++ critiquebrainz/frontend/templates/macros.html | 7 +++++ .../frontend/templates/recording/entity.html | 22 ++++++++++++++++ .../frontend/templates/review/browse.html | 2 ++ .../templates/review/entity/recording.html | 24 +++++++++++++++++ .../templates/review/modify/recording.html | 26 +++++++++++++++++++ .../frontend/templates/search/selector.html | 1 + .../templates/search/selector_results.html | 6 ++--- 11 files changed, 97 insertions(+), 6 deletions(-) create mode 100644 critiquebrainz/frontend/templates/review/entity/recording.html create mode 100644 critiquebrainz/frontend/templates/review/modify/recording.html diff --git a/critiquebrainz/db/review.py b/critiquebrainz/db/review.py index d04a7a7b0..4071ac688 100644 --- a/critiquebrainz/db/review.py +++ b/critiquebrainz/db/review.py @@ -24,6 +24,7 @@ "work", "artist", "label", + "recording" ] supported_languages = [] diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 4b33f0f6e..c43f58e07 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -12,11 +12,12 @@ def get_recording_by_id(mbid): Dictionary containing the recording information """ key = cache.gen_key(mbid) - recording = cache.get(key) + recording = False if not recording: recording = fetch_multiple_recordings( [mbid], - includes=['artist-rels', 'work-rels', 'url-rels'], + includes=['artist', '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 diff --git a/critiquebrainz/frontend/static/styles/main.less b/critiquebrainz/frontend/static/styles/main.less index 9c5477637..79aaca11d 100644 --- a/critiquebrainz/frontend/static/styles/main.less +++ b/critiquebrainz/frontend/static/styles/main.less @@ -11,6 +11,7 @@ // Entity colors @rg-color: @blue; @artist-color: @blue; +@recording-color: @blue; @event-color: @green; @place-color: @yellow; @work-color: @blue; @@ -136,6 +137,9 @@ ul.sharing { &.artist { background-color: fade(@artist-color, 70%); } + &.recording { + background-color: fade(@recording-color, 70%); + } &.work { background-color: fade(@work-color, 70%); } @@ -510,6 +514,9 @@ a#edit-review { margin-top: 20px; } &.artist { background-color: fade(@artist-color, 70%); } + &.recording { + background-color: fade(@recording-color, 70%); + } &.work { background-color: fade(@work-color, 70%); } diff --git a/critiquebrainz/frontend/templates/entity_review.html b/critiquebrainz/frontend/templates/entity_review.html index c41108387..a8956200d 100644 --- a/critiquebrainz/frontend/templates/entity_review.html +++ b/critiquebrainz/frontend/templates/entity_review.html @@ -7,6 +7,8 @@ {{ _('%(artist)s', artist = ''|safe + entity.name | default(_('[Unknown artist]')) + ''|safe) }} {% elif review.entity_type == 'label' %} {{ _('%(label)s', label = ''|safe + entity.name | default(_('[Unknown label]')) + ''|safe) }} + {% elif review.entity_type == 'recording' %} + {{ _('%(recording)s', recording = ''|safe + entity.name | default(_('[Unknown recording]')) + ''|safe) }} {% elif review.entity_type == 'event' %} {{ _('%(event)s', event = ''|safe + entity.name | default(_('[Unknown event]')) + ''|safe) }} {% elif review.entity_type == 'place' %} diff --git a/critiquebrainz/frontend/templates/macros.html b/critiquebrainz/frontend/templates/macros.html index 8eb61eae7..25fab1866 100644 --- a/critiquebrainz/frontend/templates/macros.html +++ b/critiquebrainz/frontend/templates/macros.html @@ -67,6 +67,13 @@ {{ _('Label') }} {% endif %} + {% elif entity_type == 'recording' %} + + {% if overlay_type %} + + {{ _('Recording') }} + + {% endif %} {% else %} {# release-group #} {% if overlay_type %} diff --git a/critiquebrainz/frontend/templates/recording/entity.html b/critiquebrainz/frontend/templates/recording/entity.html index 21f5da261..a0a752aa3 100644 --- a/critiquebrainz/frontend/templates/recording/entity.html +++ b/critiquebrainz/frontend/templates/recording/entity.html @@ -1 +1,23 @@ {% extends 'base.html' %} + +{# {% block title %}{{ event.name }} - CritiqueBrainz{% endblock %} #} + +{% block content %} +
+

+ {# {{ event.name }} #} +

+ + {% if not my_review %} + + {{ _('Write a review') }} + + {% else %} + + {{ _('Edit my review') }} + + {% endif %} +
+{% endblock %} diff --git a/critiquebrainz/frontend/templates/review/browse.html b/critiquebrainz/frontend/templates/review/browse.html index 722e7ba6a..f6576799e 100644 --- a/critiquebrainz/frontend/templates/review/browse.html +++ b/critiquebrainz/frontend/templates/review/browse.html @@ -15,6 +15,8 @@

{{ _('Reviews') }}

{{ _('Artist') }}
  • {{ _('Label') }}
  • +
  • + {{ _('Recording') }}
  • {{ _('Event') }}
  • diff --git a/critiquebrainz/frontend/templates/review/entity/recording.html b/critiquebrainz/frontend/templates/review/entity/recording.html new file mode 100644 index 000000000..31e2d87e2 --- /dev/null +++ b/critiquebrainz/frontend/templates/review/entity/recording.html @@ -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 %} +

    + {% if recording %} + {% set recording_name = '' | safe % url_for('recording.entity', id=review.entity_id) ~ recording.name ~ ''|safe %} + {% else %} + {% set recording_name = _('[Unknown recording]') %} + {% endif %} + + {{ _('%(recording)s', recording=recording_name) }} + + {% if recording['life-span'] %} + {{ recording['life-span']['begin'][:4] }} + {% endif %} +

    +{% endblock %} diff --git a/critiquebrainz/frontend/templates/review/modify/recording.html b/critiquebrainz/frontend/templates/review/modify/recording.html new file mode 100644 index 000000000..c888fc210 --- /dev/null +++ b/critiquebrainz/frontend/templates/review/modify/recording.html @@ -0,0 +1,26 @@ +{% if entity is not defined %} + {% set entity = review.entity_id | entity_details(type=entity_type) %} +{% endif %} +
    +
    +
    {{ _('Recording') }}
    +
    + {{ entity['name'] | default(_('[Unknown recording]')) }} +
    +
    {{ _('Length') }}
    +
    + {% if entity['length'] %} + {{ entity['length'] | track_length }} + {% else %} + - + {% endif %} +
    +
    {{ _('Artist') }}
    +
    + {{ entity['artist'] or '-' }} +
    + {% block more_info %} + {# Information like creation date, votes etc. #} + {% endblock %} +
    +
    diff --git a/critiquebrainz/frontend/templates/search/selector.html b/critiquebrainz/frontend/templates/search/selector.html index c13645800..1096efa0b 100644 --- a/critiquebrainz/frontend/templates/search/selector.html +++ b/critiquebrainz/frontend/templates/search/selector.html @@ -239,6 +239,7 @@

    {{ _('Recording selection') }}

    {{ _('Length') }} {{ _('Artist') }} {{ _('Release group') }} + {% endif %} diff --git a/critiquebrainz/frontend/templates/search/selector_results.html b/critiquebrainz/frontend/templates/search/selector_results.html index ad306eb6a..c6c13f956 100644 --- a/critiquebrainz/frontend/templates/search/selector_results.html +++ b/critiquebrainz/frontend/templates/search/selector_results.html @@ -138,7 +138,7 @@ {% elif type=="recording" %} - {{ result['name'] }} + {{ result['title'] }} {% if result['length'] %} @@ -152,9 +152,7 @@ {% if result['release-list'] %} - - {{ result['release-list'][0].title or '-' }} - + {{ result['release-list'][0].title or '-' }} {% else %} - {% endif %} From 5a15ee41263ded37f3a17785ed86fe580956d21d Mon Sep 17 00:00:00 2001 From: spellew Date: Sat, 22 Jun 2019 19:29:42 -0400 Subject: [PATCH 06/28] Fixed bug in recording retrieval --- critiquebrainz/frontend/external/musicbrainz_db/recording.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index c43f58e07..75bd178dd 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -12,7 +12,7 @@ def get_recording_by_id(mbid): Dictionary containing the recording information """ key = cache.gen_key(mbid) - recording = False + recording = cache.get(key) if not recording: recording = fetch_multiple_recordings( [mbid], From c747133e5d1644387a82ee97be93b4887370949d Mon Sep 17 00:00:00 2001 From: spellew Date: Thu, 4 Jul 2019 20:32:19 -0400 Subject: [PATCH 07/28] Fixed tests --- .../frontend/external/musicbrainz_db/recording.py | 2 +- critiquebrainz/frontend/views/recording.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 75bd178dd..96955727c 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -18,6 +18,6 @@ def get_recording_by_id(mbid): [mbid], includes=['artist', 'work-rels', 'url-rels'], ).get(mbid) - recording.update({ 'length': recording['length'] * 1000.0 }) + recording.update({'length': recording['length'] * 1000.0}) cache.set(key=key, val=recording, time=DEFAULT_CACHE_EXPIRATION) return recording diff --git a/critiquebrainz/frontend/views/recording.py b/critiquebrainz/frontend/views/recording.py index 126963fec..789749258 100644 --- a/critiquebrainz/frontend/views/recording.py +++ b/critiquebrainz/frontend/views/recording.py @@ -16,15 +16,16 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from flask import Blueprint, render_template, request -from flask_login import current_user -from flask_babel import gettext +from flask import Blueprint, render_template +# from flask import request +# from flask_login import current_user from werkzeug.exceptions import NotFound +from flask_babel import gettext import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions -import critiquebrainz.db.review as db_review -from critiquebrainz.frontend.forms.rate import RatingEditForm -from critiquebrainz.frontend.views import get_avg_rating +# import critiquebrainz.db.review as db_review +# from critiquebrainz.frontend.forms.rate import RatingEditForm +# from critiquebrainz.frontend.views import get_avg_rating recording_bp = Blueprint('recording', __name__) From 5d321cd97f49849856e0fd25dfd7a9681f1dd721 Mon Sep 17 00:00:00 2001 From: spellew Date: Thu, 4 Jul 2019 21:51:19 -0400 Subject: [PATCH 08/28] Commented out AB link --- critiquebrainz/frontend/templates/release_group/entity.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/critiquebrainz/frontend/templates/release_group/entity.html b/critiquebrainz/frontend/templates/release_group/entity.html index 96ebaa3c7..35f1aa7db 100644 --- a/critiquebrainz/frontend/templates/release_group/entity.html +++ b/critiquebrainz/frontend/templates/release_group/entity.html @@ -113,6 +113,9 @@

    {{ _('Tracklist') }}

    {{ track.number }} + {{ track.recording_title }} From bd07a6bebec4f67b48c4b70887690264c39a5263 Mon Sep 17 00:00:00 2001 From: spellew Date: Mon, 5 Aug 2019 18:07:46 -0400 Subject: [PATCH 09/28] Removed comments and unused imports --- critiquebrainz/frontend/views/recording.py | 26 +--------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/critiquebrainz/frontend/views/recording.py b/critiquebrainz/frontend/views/recording.py index 789749258..ab25ca3c3 100644 --- a/critiquebrainz/frontend/views/recording.py +++ b/critiquebrainz/frontend/views/recording.py @@ -1,32 +1,8 @@ -# critiquebrainz - Repository for Creative Commons licensed reviews -# -# Copyright (C) 2018 MetaBrainz Foundation Inc. -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - from flask import Blueprint, render_template -# from flask import request -# from flask_login import current_user from werkzeug.exceptions import NotFound from flask_babel import gettext import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions -# import critiquebrainz.db.review as db_review -# from critiquebrainz.frontend.forms.rate import RatingEditForm -# from critiquebrainz.frontend.views import get_avg_rating - recording_bp = Blueprint('recording', __name__) @@ -37,6 +13,6 @@ def entity(id): try: recording = mb_recording.get_recording_by_id(id) except mb_exceptions.NoDataFoundException: - raise NotFound(gettext("Sorry, we couldn't find a release group with that MusicBrainz ID.")) + raise NotFound(gettext("Sorry, we couldn't find a recording with that MusicBrainz ID.")) return render_template('recording/entity.html', id=recording['id'], recording=recording) From c20af3f3b2ad7eb2ec120756ddbcb7d00c5dbd84 Mon Sep 17 00:00:00 2001 From: spellew Date: Thu, 15 Aug 2019 12:11:31 -0400 Subject: [PATCH 10/28] Moved alter type sql script to it's own file --- admin/schema_changes/16.sql | 1 - admin/schema_changes/18.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 admin/schema_changes/18.sql diff --git a/admin/schema_changes/16.sql b/admin/schema_changes/16.sql index fd697495f..b1f4e5377 100644 --- a/admin/schema_changes/16.sql +++ b/admin/schema_changes/16.sql @@ -1,2 +1 @@ ALTER TYPE entity_types ADD VALUE 'artist' AFTER 'place'; -ALTER TYPE entity_types ADD VALUE 'recording' AFTER 'artist'; diff --git a/admin/schema_changes/18.sql b/admin/schema_changes/18.sql new file mode 100644 index 000000000..15a154731 --- /dev/null +++ b/admin/schema_changes/18.sql @@ -0,0 +1 @@ +ALTER TYPE entity_types ADD VALUE 'recording' AFTER 'label'; From 5a8e559e6d5b9386f8888dd67ff4e3affcc952de Mon Sep 17 00:00:00 2001 From: spellew Date: Thu, 15 Aug 2019 14:33:59 -0400 Subject: [PATCH 11/28] Updated recording entity page to display relevant information --- .../external/musicbrainz_db/recording.py | 2 +- .../frontend/templates/recording/entity.html | 147 ++++++++++++++++-- critiquebrainz/frontend/views/recording.py | 39 ++++- 3 files changed, 170 insertions(+), 18 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 96955727c..4431948cf 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -16,7 +16,7 @@ def get_recording_by_id(mbid): if not recording: recording = fetch_multiple_recordings( [mbid], - includes=['artist', 'work-rels', 'url-rels'], + 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) diff --git a/critiquebrainz/frontend/templates/recording/entity.html b/critiquebrainz/frontend/templates/recording/entity.html index a0a752aa3..824c9833a 100644 --- a/critiquebrainz/frontend/templates/recording/entity.html +++ b/critiquebrainz/frontend/templates/recording/entity.html @@ -1,23 +1,140 @@ {% extends 'base.html' %} +{% from 'macros.html' import show_avg_rating, entity_rate_form, show_external_reviews with context %} -{# {% block title %}{{ event.name }} - CritiqueBrainz{% endblock %} #} +{% block title %} + {{ _('Recording "%(name)s" by %(artist)s', name=recording.name, artist=recording['artist-credit-phrase']) }} + - CritiqueBrainz +{% endblock %} {% block content %} -
    -

    - {# {{ event.name }} #} -

    - - {% if not my_review %} - - {{ _('Write a review') }} - +
    +

    + {% set artist = [] %} + {% for credit in recording['artists'] %} + {% if credit.name %} + {% do artist.append(''|safe % url_for('artist.entity', mbid=credit.id) ~ credit.name ~ ''|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()) }} +

    + + {% if not my_review %} + + {{ _('Write a review') }} + + {% else %} + + {{ _('Edit my review') }} + + {% endif %} +
    + +
    +
    + {{ entity_rate_form('recording', 'recording') }} +

    +

    {{ _('Reviews') }}

    + {% if not reviews %} +

    {{ _('No reviews found') }}

    {% else %} - - {{ _('Edit my review') }} - + + + + + + + + + + {% for review in reviews %} + + + + + + {% endfor %} + +
    {{ _('Published on') }}{{ _('Votes (+/-)') }}
    + + {{ _('by %(reviewer)s', reviewer=' '|safe % review.user.avatar + review.user.display_name) }} + + {{ review.published_on | date }}{{ review.votes_positive_count }}/{{ review.votes_negative_count }}
    +
      + {% 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 %} +
    • + {{ p+1 }} +
    • + {% endfor %} + {% endif %} +
    + {% endif %} +
    + +
    +

    {{ _('Recording information') }}

    + {% if avg_rating %} +
    + {{ show_avg_rating(avg_rating.rating, avg_rating.count) }} +
    + {% endif %} + {% if external_reviews %} + {{ _('External reviews') }} + + {% endif %} + {% if recording['external-urls'] %} + {{ _('External links') }} + {% endif %} + +
    +
    +{% endblock %} + +{% block scripts %} + + + {% endblock %} diff --git a/critiquebrainz/frontend/views/recording.py b/critiquebrainz/frontend/views/recording.py index ab25ca3c3..f7db58d74 100644 --- a/critiquebrainz/frontend/views/recording.py +++ b/critiquebrainz/frontend/views/recording.py @@ -1,8 +1,13 @@ -from flask import Blueprint, render_template +from flask import Blueprint, render_template, request +from flask_login import current_user from werkzeug.exceptions import NotFound from flask_babel import gettext +import critiquebrainz.db.review as db_review import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions +from critiquebrainz.frontend.forms.rate import RatingEditForm +from critiquebrainz.frontend.views import get_avg_rating + recording_bp = Blueprint('recording', __name__) @@ -15,4 +20,34 @@ def entity(id): except mb_exceptions.NoDataFoundException: raise NotFound(gettext("Sorry, we couldn't find a recording with that MusicBrainz ID.")) - return render_template('recording/entity.html', id=recording['id'], recording=recording) + if 'url-rels' in recording: + external_reviews = list(filter(lambda rel: rel['type'] == 'review', recording['url-rels'])) + else: + external_reviews = [] + + limit = int(request.args.get('limit', default=10)) + offset = int(request.args.get('offset', default=0)) + if current_user.is_authenticated: + my_reviews, my_count = db_review.list_reviews( + entity_id=recording['id'], + entity_type='recording', + user_id=current_user.id, + ) + my_review = my_reviews[0] if my_count else None + else: + my_review = None + reviews, count = db_review.list_reviews( + entity_id=recording['id'], + entity_type='recording', + sort='popularity', + limit=limit, + offset=offset, + ) + avg_rating = get_avg_rating(recording['id'], "recording") + + rating_form = RatingEditForm(entity_id=id, entity_type='recording') + rating_form.rating.data = my_review['rating'] if my_review else None + + return render_template('recording/entity.html', id=recording['id'], recording=recording, reviews=reviews, + my_review=my_review, external_reviews=external_reviews, limit=limit, offset=offset, + count=count, avg_rating=avg_rating, rating_form=rating_form, current_user=current_user) From 074b57bbd858fcdc314b1c180bb26e68dca46b49 Mon Sep 17 00:00:00 2001 From: spellew Date: Sun, 18 Aug 2019 15:24:00 -0400 Subject: [PATCH 12/28] Removed AcousticBrainz link from release_group entity page --- critiquebrainz/frontend/templates/release_group/entity.html | 3 --- 1 file changed, 3 deletions(-) diff --git a/critiquebrainz/frontend/templates/release_group/entity.html b/critiquebrainz/frontend/templates/release_group/entity.html index 35f1aa7db..96ebaa3c7 100644 --- a/critiquebrainz/frontend/templates/release_group/entity.html +++ b/critiquebrainz/frontend/templates/release_group/entity.html @@ -113,9 +113,6 @@

    {{ _('Tracklist') }}

    {{ track.number }} - {{ track.recording_title }} From 4cd1187a6e4a42fc6ac34db3b04be2ce6e015b62 Mon Sep 17 00:00:00 2001 From: spellew Date: Tue, 20 Aug 2019 09:13:43 -0400 Subject: [PATCH 13/28] Added titles for recording, artist, and label to user template --- .../frontend/templates/user/reviews.html | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/critiquebrainz/frontend/templates/user/reviews.html b/critiquebrainz/frontend/templates/user/reviews.html index 4dc3db463..e6dbdc6ab 100644 --- a/critiquebrainz/frontend/templates/user/reviews.html +++ b/critiquebrainz/frontend/templates/user/reviews.html @@ -60,6 +60,22 @@ {% endif %} ) {% endif %} + + {%- elif review.entity_type == 'recording' -%} + {{ entity.name | default(_('[Unknown recording]')) }} + - {{ entity['artist-credit-phrase'] | default(_('[Unknown artist]')) }} + + {%- elif review.entity_type == 'artist' -%} + {{ entity.name | default(_('[Unknown artist]')) }} + {% if entity['type'] %} + ({{ entity.type }}) + {% endif %} + + {%- elif review.entity_type == 'label' -%} + {{ entity.name | default(_('[Unknown label]')) }} + {% if entity['type'] %} + ({{ entity.type }}) + {% endif %} {%- endif -%} From f6585a6adf292a7b185875d814e24b7998013d3c Mon Sep 17 00:00:00 2001 From: spellew Date: Wed, 21 Aug 2019 20:34:04 -0400 Subject: [PATCH 14/28] Moved views/recording limit to __init__.py --- critiquebrainz/frontend/views/__init__.py | 1 + critiquebrainz/frontend/views/recording.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/critiquebrainz/frontend/views/__init__.py b/critiquebrainz/frontend/views/__init__.py index 017f648da..9b6cd5b36 100644 --- a/critiquebrainz/frontend/views/__init__.py +++ b/critiquebrainz/frontend/views/__init__.py @@ -4,6 +4,7 @@ ARTIST_REVIEWS_LIMIT = 5 LABEL_REVIEWS_LIMIT = 5 WORK_REVIEWS_LIMIT = 5 +RECORDING_REVIEWS_LIMIT = 10 BROWSE_RELEASE_GROUPS_LIMIT = 20 BROWSE_RECORDING_LIMIT = 10 diff --git a/critiquebrainz/frontend/views/recording.py b/critiquebrainz/frontend/views/recording.py index f7db58d74..b09b3ac6e 100644 --- a/critiquebrainz/frontend/views/recording.py +++ b/critiquebrainz/frontend/views/recording.py @@ -6,7 +6,7 @@ import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording import critiquebrainz.frontend.external.musicbrainz_db.exceptions as mb_exceptions from critiquebrainz.frontend.forms.rate import RatingEditForm -from critiquebrainz.frontend.views import get_avg_rating +from critiquebrainz.frontend.views import get_avg_rating, RECORDING_REVIEWS_LIMIT recording_bp = Blueprint('recording', __name__) @@ -25,7 +25,7 @@ def entity(id): else: external_reviews = [] - limit = int(request.args.get('limit', default=10)) + limit = int(request.args.get('limit', default=RECORDING_REVIEWS_LIMIT)) offset = int(request.args.get('offset', default=0)) if current_user.is_authenticated: my_reviews, my_count = db_review.list_reviews( From 39e91f11b9598809a9af5b992031d85f00edf56f Mon Sep 17 00:00:00 2001 From: spellew Date: Wed, 21 Aug 2019 21:04:48 -0400 Subject: [PATCH 15/28] Created separate track_length functions for seconds and milliseconds --- critiquebrainz/frontend/external/musicbrainz_db/recording.py | 1 - critiquebrainz/frontend/templates/review/modify/recording.html | 2 +- critiquebrainz/frontend/templates/search/results.html | 2 +- critiquebrainz/frontend/templates/search/selector_results.html | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 4431948cf..ff1e3fb3b 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -18,6 +18,5 @@ def get_recording_by_id(mbid): [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 diff --git a/critiquebrainz/frontend/templates/review/modify/recording.html b/critiquebrainz/frontend/templates/review/modify/recording.html index c888fc210..40343417b 100644 --- a/critiquebrainz/frontend/templates/review/modify/recording.html +++ b/critiquebrainz/frontend/templates/review/modify/recording.html @@ -10,7 +10,7 @@
    {{ _('Length') }}
    {% if entity['length'] %} - {{ entity['length'] | track_length }} + {{ entity['length'] | track_length_ms }} {% else %} - {% endif %} diff --git a/critiquebrainz/frontend/templates/search/results.html b/critiquebrainz/frontend/templates/search/results.html index 316b1b7d1..45df626c3 100644 --- a/critiquebrainz/frontend/templates/search/results.html +++ b/critiquebrainz/frontend/templates/search/results.html @@ -108,7 +108,7 @@ {% if result['length'] %} - {{ result['length'] | track_length }} + {{ result['length'] | track_length_ms }} {% else %} - {% endif %} diff --git a/critiquebrainz/frontend/templates/search/selector_results.html b/critiquebrainz/frontend/templates/search/selector_results.html index c6c13f956..0cd3a759b 100644 --- a/critiquebrainz/frontend/templates/search/selector_results.html +++ b/critiquebrainz/frontend/templates/search/selector_results.html @@ -142,7 +142,7 @@ {% if result['length'] %} - {{ result['length'] | track_length }} + {{ result['length'] | track_length_ms }} {% else %} - {% endif %} From f900b332d0de9d3790b2d6bd05a62460cbf3dd24 Mon Sep 17 00:00:00 2001 From: spellew Date: Sat, 24 Aug 2019 11:41:50 -0400 Subject: [PATCH 16/28] Fixed track list in review/modify --- critiquebrainz/frontend/templates/review/modify/recording.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/templates/review/modify/recording.html b/critiquebrainz/frontend/templates/review/modify/recording.html index 40343417b..c888fc210 100644 --- a/critiquebrainz/frontend/templates/review/modify/recording.html +++ b/critiquebrainz/frontend/templates/review/modify/recording.html @@ -10,7 +10,7 @@
    {{ _('Length') }}
    {% if entity['length'] %} - {{ entity['length'] | track_length_ms }} + {{ entity['length'] | track_length }} {% else %} - {% endif %} From 2c476696350cefa3965cc206d78224d97cf1c648 Mon Sep 17 00:00:00 2001 From: spellew Date: Sat, 24 Aug 2019 11:59:41 -0400 Subject: [PATCH 17/28] Fixed artist in review/modify --- critiquebrainz/frontend/templates/review/modify/recording.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/templates/review/modify/recording.html b/critiquebrainz/frontend/templates/review/modify/recording.html index c888fc210..da6a30925 100644 --- a/critiquebrainz/frontend/templates/review/modify/recording.html +++ b/critiquebrainz/frontend/templates/review/modify/recording.html @@ -17,7 +17,7 @@
    {{ _('Artist') }}
    - {{ entity['artist'] or '-' }} + {{ entity['artist-credit-phrase'] or '-' }}
    {% block more_info %} {# Information like creation date, votes etc. #} From 0d47350429251ed1c0ae68987df1a89666c781e9 Mon Sep 17 00:00:00 2001 From: spellew Date: Tue, 27 Aug 2019 11:06:14 -0400 Subject: [PATCH 18/28] Removed unnecessary code --- .../frontend/templates/review/entity/recording.html | 4 ---- 1 file changed, 4 deletions(-) diff --git a/critiquebrainz/frontend/templates/review/entity/recording.html b/critiquebrainz/frontend/templates/review/entity/recording.html index 31e2d87e2..f495299ef 100644 --- a/critiquebrainz/frontend/templates/review/entity/recording.html +++ b/critiquebrainz/frontend/templates/review/entity/recording.html @@ -16,9 +16,5 @@

    {% endif %} {{ _('%(recording)s', recording=recording_name) }} - - {% if recording['life-span'] %} - {{ recording['life-span']['begin'][:4] }} - {% endif %}

    {% endblock %} From afc8eab3dbd2b81f2b012be197982f0bd22473e1 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Thu, 31 Dec 2020 14:18:24 +0530 Subject: [PATCH 19/28] Use get_*_by_id instead of fetch_multiple_* --- .../external/musicbrainz_db/artist.py | 6 +-- .../frontend/external/musicbrainz_db/event.py | 6 +-- .../frontend/external/musicbrainz_db/label.py | 6 +-- .../frontend/external/musicbrainz_db/place.py | 6 +-- .../external/musicbrainz_db/recording.py | 9 ++-- .../external/musicbrainz_db/release.py | 6 +-- .../external/musicbrainz_db/release_group.py | 6 +-- .../musicbrainz_db/test/test_cache.py | 42 +++++++++---------- .../frontend/external/musicbrainz_db/work.py | 6 +-- 9 files changed, 47 insertions(+), 46 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/artist.py b/critiquebrainz/frontend/external/musicbrainz_db/artist.py index 5443a6973..304e59bd5 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/artist.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/artist.py @@ -16,10 +16,10 @@ def get_artist_by_id(mbid): key = cache.gen_key('artist', mbid) artist = cache.get(key) if not artist: - artist = db.fetch_multiple_artists( - [mbid], + artist = db.get_artist_by_id( + mbid, includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True, - ).get(mbid) + ) cache.set(key=key, val=artist, time=DEFAULT_CACHE_EXPIRATION) return artist_rel.process(artist) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/event.py b/critiquebrainz/frontend/external/musicbrainz_db/event.py index 114c018e9..025c16395 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/event.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/event.py @@ -15,10 +15,10 @@ def get_event_by_id(mbid): key = cache.gen_key('event', mbid) event = cache.get(key) if not event: - event = db.fetch_multiple_events( - [mbid], + event = db.get_event_by_id( + mbid, includes=['artist-rels', 'place-rels', 'series-rels', 'url-rels', 'release-group-rels'], unknown_entities_for_missing=True, - ).get(mbid) + ) cache.set(key=key, val=event, time=DEFAULT_CACHE_EXPIRATION) return event diff --git a/critiquebrainz/frontend/external/musicbrainz_db/label.py b/critiquebrainz/frontend/external/musicbrainz_db/label.py index 0b34cd7c9..a9bf4c26b 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/label.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/label.py @@ -16,10 +16,10 @@ def get_label_by_id(mbid): key = cache.gen_key('label', mbid) label = cache.get(key) if not label: - label = db.fetch_multiple_labels( - [mbid], + label = db.get_label_by_id( + mbid, includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True - ).get(mbid) + ) cache.set(key=key, val=label, time=DEFAULT_CACHE_EXPIRATION) return label_rel.process(label) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/place.py b/critiquebrainz/frontend/external/musicbrainz_db/place.py index 8a86fa0b1..f3c0118be 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/place.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/place.py @@ -16,10 +16,10 @@ def get_place_by_id(mbid): key = cache.gen_key('place', mbid) place = cache.get(key) if not place: - place = db.fetch_multiple_places( - [mbid], + place = db.get_place_by_id( + mbid, includes=['artist-rels', 'place-rels', 'release-group-rels', 'url-rels'], unknown_entities_for_missing=True, - ).get(mbid) + ) cache.set(key=key, val=place, time=DEFAULT_CACHE_EXPIRATION) return place_rel.process(place) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index ff1e3fb3b..5da25723b 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -1,5 +1,6 @@ from brainzutils import cache -from brainzutils.musicbrainz_db.recording import fetch_multiple_recordings +from brainzutils.musicbrainz_db import recording as db + from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION @@ -14,9 +15,9 @@ def get_recording_by_id(mbid): key = cache.gen_key(mbid) recording = cache.get(key) if not recording: - recording = fetch_multiple_recordings( - [mbid], + recording = db.get_recording_by_id( + mbid, includes=['artists', 'work-rels', 'url-rels'], - ).get(mbid) + ) cache.set(key=key, val=recording, time=DEFAULT_CACHE_EXPIRATION) return recording diff --git a/critiquebrainz/frontend/external/musicbrainz_db/release.py b/critiquebrainz/frontend/external/musicbrainz_db/release.py index ffa1029d9..b09725bdb 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/release.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/release.py @@ -15,10 +15,10 @@ def get_release_by_id(mbid): key = cache.gen_key('release', mbid) release = cache.get(key) if not release: - release = db.fetch_multiple_releases( - [mbid], + release = db.get_release_by_id( + mbid, includes=['media', 'release-groups'], unknown_entities_for_missing=True, - ).get(mbid) + ) cache.set(key=key, val=release, time=DEFAULT_CACHE_EXPIRATION) return release diff --git a/critiquebrainz/frontend/external/musicbrainz_db/release_group.py b/critiquebrainz/frontend/external/musicbrainz_db/release_group.py index 1da48d924..990a6bf5e 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/release_group.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/release_group.py @@ -10,11 +10,11 @@ def get_release_group_by_id(mbid): key = cache.gen_key('release-group', mbid) release_group = cache.get(key) if not release_group: - release_group = db.fetch_multiple_release_groups( - [mbid], + release_group = db.get_release_group_by_id( + mbid, includes=['artists', 'releases', 'release-group-rels', 'url-rels', 'tags'], unknown_entities_for_missing=True, - )[mbid] + ) cache.set(key=key, val=release_group, time=DEFAULT_CACHE_EXPIRATION) return release_group_rel.process(release_group) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py index 062e66425..4c8350352 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py @@ -16,7 +16,7 @@ class CacheTestCase(DataTestCase): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.artist.fetch_multiple_artists') + @mock.patch('brainzutils.musicbrainz_db.artist.get_artist_by_id') def test_artist_cache(self, artist_fetch, cache_set, cache_get): mbid = "f59c5520-5f46-4d2c-b2c4-822eabf53419" expected_key = b"artist_f59c5520-5f46-4d2c-b2c4-822eabf53419" @@ -26,14 +26,14 @@ def test_artist_cache(self, artist_fetch, cache_set, cache_get): "sort_name": "Linkin Park", "type": "Group" } - artist_fetch.return_value = {mbid: artist} + artist_fetch.return_value = artist cache_get.return_value = None get_artist_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - artist_fetch.assert_called_with([mbid], includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True) + artist_fetch.assert_called_with(mbid, includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=artist, time=DEFAULT_CACHE_EXPIRATION) cache_get.return_value = artist @@ -48,7 +48,7 @@ def test_artist_cache(self, artist_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.event.fetch_multiple_events') + @mock.patch('brainzutils.musicbrainz_db.event.get_event_by_id') def test_event_cache(self, event_fetch, cache_set, cache_get): mbid = "ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94" expected_key = b"event_ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94" @@ -56,14 +56,14 @@ def test_event_cache(self, event_fetch, cache_set, cache_get): 'id': 'ebe6ce0f-22c0-4fe7-bfd4-7a0397c9fe94', 'name': 'Taubertal-Festival 2004, Day 1', } - event_fetch.return_value = {mbid: event} + event_fetch.return_value = event cache_get.return_value = None get_event_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - event_fetch.assert_called_with([mbid], includes=['artist-rels', 'place-rels', + event_fetch.assert_called_with(mbid, includes=['artist-rels', 'place-rels', 'series-rels', 'url-rels', 'release-group-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=event, time=DEFAULT_CACHE_EXPIRATION) @@ -80,7 +80,7 @@ def test_event_cache(self, event_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.label.fetch_multiple_labels') + @mock.patch('brainzutils.musicbrainz_db.label.get_label_by_id') def test_label_cache(self, label_fetch, cache_set, cache_get): mbid = "1aed8c3b-8e1e-46f8-b558-06357ff5f298" expected_key = b"label_1aed8c3b-8e1e-46f8-b558-06357ff5f298" @@ -90,14 +90,14 @@ def test_label_cache(self, label_fetch, cache_set, cache_get): "type": "Imprint", "area": "United States", } - label_fetch.return_value = {mbid: label} + label_fetch.return_value = label cache_get.return_value = None get_label_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - label_fetch.assert_called_with([mbid], includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True) + label_fetch.assert_called_with(mbid, includes=['artist-rels', 'url-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=label, time=DEFAULT_CACHE_EXPIRATION) cache_get.return_value = label @@ -112,7 +112,7 @@ def test_label_cache(self, label_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.place.fetch_multiple_places') + @mock.patch('brainzutils.musicbrainz_db.place.get_place_by_id') def test_place_cache(self, place_fetch, cache_set, cache_get): mbid = "d71ffe38-5eaf-426b-9a2e-e1f21bc84609" expected_key = b"place_d71ffe38-5eaf-426b-9a2e-e1f21bc84609" @@ -128,14 +128,14 @@ def test_place_cache(self, place_fetch, cache_set, cache_get): "name": "Hämeenlinna", } } - place_fetch.return_value = {mbid: place} + place_fetch.return_value = place cache_get.return_value = None get_place_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - place_fetch.assert_called_with([mbid], includes=['artist-rels', 'place-rels', + place_fetch.assert_called_with(mbid, includes=['artist-rels', 'place-rels', 'release-group-rels', 'url-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=place, time=DEFAULT_CACHE_EXPIRATION) @@ -152,7 +152,7 @@ def test_place_cache(self, place_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.release.fetch_multiple_releases') + @mock.patch('brainzutils.musicbrainz_db.release.get_release_by_id') def test_release_cache(self, release_fetch, cache_set, cache_get): mbid = "16bee711-d7ce-48b0-adf4-51f124bcc0df" expected_key = b"release_16bee711-d7ce-48b0-adf4-51f124bcc0df" @@ -171,14 +171,14 @@ def test_release_cache(self, release_fetch, cache_set, cache_get): }] }] } - release_fetch.return_value = {mbid: release} + release_fetch.return_value = release cache_get.return_value = None get_release_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - release_fetch.assert_called_with([mbid], includes=['media', 'release-groups'], unknown_entities_for_missing=True) + release_fetch.assert_called_with(mbid, includes=['media', 'release-groups'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=release, time=DEFAULT_CACHE_EXPIRATION) cache_get.return_value = release @@ -193,7 +193,7 @@ def test_release_cache(self, release_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.release_group.fetch_multiple_release_groups') + @mock.patch('brainzutils.musicbrainz_db.release_group.get_release_group_by_id') def test_release_group_cache(self, release_group_fetch, cache_set, cache_get): mbid = "7c1014eb-454c-3867-8854-3c95d265f8de" expected_key = b"release-group_7c1014eb-454c-3867-8854-3c95d265f8de" @@ -211,14 +211,14 @@ def test_release_group_cache(self, release_group_fetch, cache_set, cache_get): 'join_phrase': '/', }] } - release_group_fetch.return_value = {mbid: release_group} + release_group_fetch.return_value = release_group cache_get.return_value = None get_release_group_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - release_group_fetch.assert_called_with([mbid], includes=['artists', 'releases', + release_group_fetch.assert_called_with(mbid, includes=['artists', 'releases', 'release-group-rels', 'url-rels', 'tags'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=release_group, time=DEFAULT_CACHE_EXPIRATION) @@ -235,7 +235,7 @@ def test_release_group_cache(self, release_group_fetch, cache_set, cache_get): @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') - @mock.patch('brainzutils.musicbrainz_db.work.fetch_multiple_works') + @mock.patch('brainzutils.musicbrainz_db.work.get_work_by_id') def test_work_cache(self, work_fetch, cache_set, cache_get): mbid = "54ce5e07-2aca-4578-83d8-5a41a7b2f434" expected_key = b"work_54ce5e07-2aca-4578-83d8-5a41a7b2f434" @@ -244,14 +244,14 @@ def test_work_cache(self, work_fetch, cache_set, cache_get): "name": "a lot", "type": "Song", } - work_fetch.return_value = {mbid: work} + work_fetch.return_value = work cache_get.return_value = None get_work_by_id(mbid) # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - work_fetch.assert_called_with([mbid], includes=['artist-rels', 'recording-rels']) + work_fetch.assert_called_with(mbid, includes=['artist-rels', 'recording-rels']) cache_set.assert_called_with(key=expected_key, val=work, time=DEFAULT_CACHE_EXPIRATION) cache_get.return_value = work diff --git a/critiquebrainz/frontend/external/musicbrainz_db/work.py b/critiquebrainz/frontend/external/musicbrainz_db/work.py index bc9238a88..b631826b4 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/work.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/work.py @@ -15,9 +15,9 @@ def get_work_by_id(mbid): key = cache.gen_key('work', mbid) work = cache.get(key) if not work: - work = db.fetch_multiple_works( - [mbid], + work = db.get_work_by_id( + mbid, includes=['artist-rels', 'recording-rels'], - ).get(mbid) + ) cache.set(key=key, val=work, time=DEFAULT_CACHE_EXPIRATION) return work From 74403083a509be59360c5ea276994e2cc371e50b Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Thu, 31 Dec 2020 14:19:29 +0530 Subject: [PATCH 20/28] Simplify filtering code --- .../frontend/external/musicbrainz_db/entities.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/entities.py b/critiquebrainz/frontend/external/musicbrainz_db/entities.py index 852e026fb..b5ea0d974 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/entities.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/entities.py @@ -19,7 +19,7 @@ def get_multiple_entities(entities): """Fetch multiple entities using their MBIDs. Args: - entites: List of tuples containing the entity ID and the entity type. + entities: List of tuples containing the entity ID and the entity type. Returns: Dictionary containing the basic information related to the entities. @@ -31,13 +31,13 @@ def get_multiple_entities(entities): coordinates of the places is also included. """ entities_info = {} - release_group_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'release_group', entities)] - artist_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'artist', entities)] - label_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'label', entities)] - recording_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'recording', entities)] - place_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'place', entities)] - event_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'event', entities)] - work_mbids = [entity[0] for entity in filter(lambda entity: entity[1] == 'work', entities)] + release_group_mbids = [entity[0] for entity in entities if entity[1] == 'release_group'] + artist_mbids = [entity[0] for entity in entities if entity[1] == 'artist'] + label_mbids = [entity[0] for entity in entities if entity[1] == 'label'] + recording_mbids = [entity[0] for entity in entities if entity[1] == 'recording'] + place_mbids = [entity[0] for entity in entities if entity[1] == 'place'] + event_mbids = [entity[0] for entity in entities if entity[1] == 'event'] + work_mbids = [entity[0] for entity in entities if entity[1] == 'work'] entities_info.update(fetch_multiple_release_groups( release_group_mbids, includes=['artists'], From 772b9f9097dc601a047c66289ce92e7e7ce9fa5e Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Thu, 31 Dec 2020 14:20:32 +0530 Subject: [PATCH 21/28] Do not put html inside strings --- .../frontend/templates/entity_review.html | 18 +++--------------- .../frontend/templates/recording/entity.html | 19 ++++++------------- .../templates/review/entity/recording.html | 6 ++---- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/critiquebrainz/frontend/templates/entity_review.html b/critiquebrainz/frontend/templates/entity_review.html index a8956200d..09ca1ae26 100644 --- a/critiquebrainz/frontend/templates/entity_review.html +++ b/critiquebrainz/frontend/templates/entity_review.html @@ -1,19 +1,7 @@ {% if review.entity_type == 'release_group' %} - {{ _('%(album)s by %(artist)s', - album = ''|safe + entity.title | default(_('[Unknown release group]')) + ''|safe, - artist = entity['artist-credit-phrase'] | default(_('[Unknown artist]'))) }} - {% elif review.entity_type == 'artist' %} - {{ _('%(artist)s', artist = ''|safe + entity.name | default(_('[Unknown artist]')) + ''|safe) }} - {% elif review.entity_type == 'label' %} - {{ _('%(label)s', label = ''|safe + entity.name | default(_('[Unknown label]')) + ''|safe) }} - {% elif review.entity_type == 'recording' %} - {{ _('%(recording)s', recording = ''|safe + entity.name | default(_('[Unknown recording]')) + ''|safe) }} - {% elif review.entity_type == 'event' %} - {{ _('%(event)s', event = ''|safe + entity.name | default(_('[Unknown event]')) + ''|safe) }} - {% elif review.entity_type == 'place' %} - {{ _('%(place)s', place = ''|safe + entity.name | default(_('[Unknown place]')) + ''|safe) }} - {% elif review.entity_type == 'work' %} - {{ _('%(work)s', work = ''|safe + entity.name | default(_('[Unknown work]')) + ''|safe) }} + {{ entity.title }} {{ _('by') }} {{ entity['artist-credit-phrase'] | default(_('[Unknown artist]')) }} + {% else %} + {{ entity.name }} {% endif %} diff --git a/critiquebrainz/frontend/templates/recording/entity.html b/critiquebrainz/frontend/templates/recording/entity.html index 824c9833a..19e5216f5 100644 --- a/critiquebrainz/frontend/templates/recording/entity.html +++ b/critiquebrainz/frontend/templates/recording/entity.html @@ -9,19 +9,12 @@ {% block content %}

    - {% set artist = [] %} + {{ recording.name }} {{ _('by') }} {% for credit in recording['artists'] %} - {% if credit.name %} - {% do artist.append(''|safe % url_for('artist.entity', mbid=credit.id) ~ credit.name ~ ''|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()) }} + {% if credit.name %} + {{ credit.name }} + {% if credit.join_phrase %}{{ credit.join_phrase }}{% endif %} + {% endif %}

    {% if not my_review %} @@ -58,7 +51,7 @@

    {{ _('Reviews') }}

    - {{ _('by %(reviewer)s', reviewer=' '|safe % review.user.avatar + review.user.display_name) }} + {{ _('by') }} {{ review.published_on | date }} diff --git a/critiquebrainz/frontend/templates/review/entity/recording.html b/critiquebrainz/frontend/templates/review/entity/recording.html index f495299ef..7543c966b 100644 --- a/critiquebrainz/frontend/templates/review/entity/recording.html +++ b/critiquebrainz/frontend/templates/review/entity/recording.html @@ -10,11 +10,9 @@ {% block entity_title %}

    {% if recording %} - {% set recording_name = '' | safe % url_for('recording.entity', id=review.entity_id) ~ recording.name ~ ''|safe %} + recording.name {% else %} - {% set recording_name = _('[Unknown recording]') %} + {{ _('[Unknown recording]') }} {% endif %} - - {{ _('%(recording)s', recording=recording_name) }}

    {% endblock %} From 29697de15f92ee837262c3145229caeefe74d362 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Thu, 31 Dec 2020 14:21:35 +0530 Subject: [PATCH 22/28] Remove fall thorough in macro --- critiquebrainz/frontend/templates/macros.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/templates/macros.html b/critiquebrainz/frontend/templates/macros.html index 25fab1866..1ce1454ad 100644 --- a/critiquebrainz/frontend/templates/macros.html +++ b/critiquebrainz/frontend/templates/macros.html @@ -74,7 +74,7 @@ {{ _('Recording') }} {% endif %} - {% else %} {# release-group #} + {% elif entity_type == 'release_group' %} {% if overlay_type %} From c5da00c1a7cd1bf14e5cc6adc30918012adf2cbb Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Thu, 31 Dec 2020 19:21:53 +0530 Subject: [PATCH 23/28] Extract artist credit into macro --- critiquebrainz/frontend/templates/macros.html | 16 ++++++++++ .../frontend/templates/search/results.html | 31 +++---------------- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/critiquebrainz/frontend/templates/macros.html b/critiquebrainz/frontend/templates/macros.html index 1ce1454ad..316941af6 100644 --- a/critiquebrainz/frontend/templates/macros.html +++ b/critiquebrainz/frontend/templates/macros.html @@ -204,3 +204,19 @@

    {{ _('Rate this {}:'.format(entity_type_readable)) {{ _('

    Sign in to rate!

    ', link=url_for('login.index', next=url_for('{}.entity'.format(entity_type), id=id))) }} {% endif %} {% endmacro %} + +{% macro display_artist_credit(result) %} + {% if result['artist-relation-list'] %} + {% if result['artist-credit-phrase'] %} + {{ result['artist-credit-phrase'] }} + {% else %} + {{ result['artist-relation-list'][0]['artist']['name'] or '-' }} + {% set count = result['artist-relation-list'] | length %} + {% if count > 1 %} + + {{ count - 1 }} {{ _("more") }} + {% endif %} + {% endif %} + {% else %} + - + {% endif %} +{% endmacro %} diff --git a/critiquebrainz/frontend/templates/search/results.html b/critiquebrainz/frontend/templates/search/results.html index 45df626c3..815fa48bf 100644 --- a/critiquebrainz/frontend/templates/search/results.html +++ b/critiquebrainz/frontend/templates/search/results.html @@ -1,3 +1,4 @@ +{% from 'macros.html' import display_artist_credit %} {% for result in results %} {% if type=="artist" %} @@ -17,7 +18,7 @@ {{ result['title'] }} {% if result['disambiguation'] %}({{ result['disambiguation'] }}){% endif %} - {{ result['artist-credit-phrase'] }} + {{ display_artist_credit(result) }} {{ result['primary-type'] or '-' }} @@ -27,17 +28,7 @@ {{ result['name'] }} {% if result['disambiguation'] %}({{ result['life-span']['begin'] }} - {{ result['life-span']['end'] }}){% endif %} - - {% if result['artist-relation-list'] %} - {{ result['artist-relation-list'][0]['artist']['name'] or '-' }} - {% set count = result['artist-relation-list'] | length %} - {% if count > 1 %} - + {{ count - 1 }} {{ _("more") }} - {% endif %} - {% else %} - - - {% endif %} - + {{ display_artist_credit(result) }} {% if result['place-relation-list'] %} {{ result['place-relation-list'][0]['place']['name'] or '-' }} @@ -69,17 +60,7 @@ {{ result['title'] }} - - {% if result['artist-relation-list'] %} - {{ result['artist-relation-list'][0]['artist']['name'] or '-' }} - {% set count = result['artist-relation-list'] | length %} - {% if count > 1 %} - + {{ count - 1 }} {{ _("more") }} - {% endif %} - {% else %} - - - {% endif %} - + {{ display_artist_credit(result) }} {{ result['type'] or '-' }} @@ -113,9 +94,7 @@ - {% endif %} - - {{ result['artist-credit'][0]['artist']['name'] or '-' }} - + {{ display_artist_credit(result) }} {% if result['release-list'] %} {{ result['release-list'][0].title or '-' }} From b7cfa2ff108971a406650e8156612e186feee0cd Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 1 Jan 2021 11:36:44 +0530 Subject: [PATCH 24/28] Add tests for recording entity --- .../musicbrainz_db/test/test_cache.py | 44 ++++++++++++++++ .../frontend/views/test/test_recording.py | 50 +++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 critiquebrainz/frontend/views/test/test_recording.py diff --git a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py index 4c8350352..bed02f10f 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py @@ -6,6 +6,7 @@ from critiquebrainz.frontend.external.musicbrainz_db.event import get_event_by_id from critiquebrainz.frontend.external.musicbrainz_db.label import get_label_by_id from critiquebrainz.frontend.external.musicbrainz_db.place import get_place_by_id +from critiquebrainz.frontend.external.musicbrainz_db.recording import get_recording_by_id from critiquebrainz.frontend.external.musicbrainz_db.release import get_release_by_id from critiquebrainz.frontend.external.musicbrainz_db.release_group import get_release_group_by_id from critiquebrainz.frontend.external.musicbrainz_db.work import get_work_by_id @@ -150,6 +151,49 @@ def test_place_cache(self, place_fetch, cache_set, cache_get): place_fetch.assert_not_called() cache_set.assert_not_called() + @mock.patch('brainzutils.cache.get') + @mock.patch('brainzutils.cache.set') + @mock.patch('brainzutils.musicbrainz_db.recording.get_recording_by_mbid') + def test_recording_cache(self, recording_fetch, cache_set, cache_get): + mbid = "442ddce2-ffa1-4865-81d2-b42c40fec7c5" + expected_key = b"recording_442ddce2-ffa1-4865-81d2-b42c40fec7c5" + recording = { + 'id': '442ddce2-ffa1-4865-81d2-b42c40fec7c5', + 'name': 'Dream Come True', + 'length': 229.0, + 'artists': [ + { + 'id': '164f0d73-1234-4e2c-8743-d77bf2191051', + 'name': 'Kanye West', + 'join_phrase': ' feat. ' + }, + { + 'id': '75a72702-a5ef-4513-bca5-c5b944903546', + 'name': 'John Legend' + } + ], + 'artist-credit-phrase': 'Kanye West feat. John Legend' + } + recording_fetch.return_value = recording + + cache_get.return_value = None + get_recording_by_id(mbid) + + # Test that first time data is fetched database is queried + cache_get.assert_called_with(expected_key) + recording_fetch.assert_called_with(mbid, includes=['artists', 'work-rels', 'url-rels']) + cache_set.assert_called_with(key=expected_key, val=recording, time=DEFAULT_CACHE_EXPIRATION) + + cache_get.return_value = recording + cache_set.reset_mock() + recording_fetch.reset_mock() + get_recording_by_id(mbid) + + # Test that second time data is fetched from cache + cache_get.assert_called_with(expected_key) + recording_fetch.assert_not_called() + cache_set.assert_not_called() + @mock.patch('brainzutils.cache.get') @mock.patch('brainzutils.cache.set') @mock.patch('brainzutils.musicbrainz_db.release.get_release_by_id') diff --git a/critiquebrainz/frontend/views/test/test_recording.py b/critiquebrainz/frontend/views/test/test_recording.py new file mode 100644 index 000000000..da80486f3 --- /dev/null +++ b/critiquebrainz/frontend/views/test/test_recording.py @@ -0,0 +1,50 @@ +from unittest.mock import MagicMock + +import critiquebrainz.db.license as db_license +import critiquebrainz.db.review as db_review +import critiquebrainz.db.users as db_users +import critiquebrainz.frontend.external.musicbrainz_db.recording as mb_recording +from critiquebrainz.db.user import User +from critiquebrainz.frontend.testing import FrontendTestCase + + +class RecordingViewsTestCase(FrontendTestCase): + + def setUp(self): + super(RecordingViewsTestCase, self).setUp() + mb_recording.get_recording_by_id = MagicMock() + mb_recording.get_recording_by_id.return_value = { + 'id': '442ddce2-ffa1-4865-81d2-b42c40fec7c5', + 'name': 'Dream Come True', + 'length': 229.0, + 'artists': [ + { + 'id': '164f0d73-1234-4e2c-8743-d77bf2191051', + 'name': 'Kanye West', + 'join_phrase': ' feat. ' + }, + { + 'id': '75a72702-a5ef-4513-bca5-c5b944903546', + 'name': 'John Legend' + } + ], + 'artist-credit-phrase': 'Kanye West feat. John Legend' + } + self.user = User(db_users.get_or_create(1, "Tester", new_user_data={"display_name": "test user"})) + self.license = db_license.create(id='Test', full_name='Test License') + + def test_recording_page(self): + db_review.create( + user_id=self.user.id, + entity_id='442ddce2-ffa1-4865-81d2-b42c40fec7c5', + entity_type='recording', + text='This is a test review', + is_draft=False, + license_id=self.license['id'], + language='en', + ) + response = self.client.get('/recording/8ef859e3-feb2-4dd1-93da-22b91280d768') + self.assert200(response) + self.assertIn('Dream Come True', str(response.data)) + # Test if there is a review from test user + self.assertIn('test user', str(response.data)) From 9b5eb0d6c0b0e5e6e64c65eb4650a62dd48963d3 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 1 Jan 2021 11:37:01 +0530 Subject: [PATCH 25/28] Fix minor bugs --- critiquebrainz/frontend/external/musicbrainz_db/recording.py | 3 +-- critiquebrainz/frontend/templates/recording/entity.html | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 5da25723b..76fcfd000 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -3,7 +3,6 @@ from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION - def get_recording_by_id(mbid): """Get recording with MusicBrainz ID. @@ -15,7 +14,7 @@ def get_recording_by_id(mbid): key = cache.gen_key(mbid) recording = cache.get(key) if not recording: - recording = db.get_recording_by_id( + recording = db.get_recording_by_mbid( mbid, includes=['artists', 'work-rels', 'url-rels'], ) diff --git a/critiquebrainz/frontend/templates/recording/entity.html b/critiquebrainz/frontend/templates/recording/entity.html index 19e5216f5..007e63f75 100644 --- a/critiquebrainz/frontend/templates/recording/entity.html +++ b/critiquebrainz/frontend/templates/recording/entity.html @@ -15,6 +15,7 @@

    {{ credit.name }} {% if credit.join_phrase %}{{ credit.join_phrase }}{% endif %} {% endif %} + {% endfor %}

    {% if not my_review %} From ab32aa0f19c97a833e5d137911f60c8d9f4b0c14 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 1 Jan 2021 12:49:50 +0530 Subject: [PATCH 26/28] Use recording also in generating cache key --- critiquebrainz/frontend/external/musicbrainz_db/recording.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/recording.py b/critiquebrainz/frontend/external/musicbrainz_db/recording.py index 76fcfd000..136929520 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/recording.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/recording.py @@ -3,6 +3,7 @@ from critiquebrainz.frontend.external.musicbrainz_db import DEFAULT_CACHE_EXPIRATION + def get_recording_by_id(mbid): """Get recording with MusicBrainz ID. @@ -11,7 +12,7 @@ def get_recording_by_id(mbid): Returns: Dictionary containing the recording information """ - key = cache.gen_key(mbid) + key = cache.gen_key('recording', mbid) recording = cache.get(key) if not recording: recording = db.get_recording_by_mbid( From 4f04b9412df85a942f48f60bc7ea2631c63062af Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Fri, 1 Jan 2021 13:06:31 +0530 Subject: [PATCH 27/28] Fix pylint warnings --- .../frontend/external/musicbrainz_db/test/test_cache.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py index bed02f10f..6abcd1a16 100644 --- a/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py +++ b/critiquebrainz/frontend/external/musicbrainz_db/test/test_cache.py @@ -65,7 +65,7 @@ def test_event_cache(self, event_fetch, cache_set, cache_get): # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) event_fetch.assert_called_with(mbid, includes=['artist-rels', 'place-rels', - 'series-rels', 'url-rels', 'release-group-rels'], + 'series-rels', 'url-rels', 'release-group-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=event, time=DEFAULT_CACHE_EXPIRATION) @@ -137,7 +137,7 @@ def test_place_cache(self, place_fetch, cache_set, cache_get): # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) place_fetch.assert_called_with(mbid, includes=['artist-rels', 'place-rels', - 'release-group-rels', 'url-rels'], + 'release-group-rels', 'url-rels'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=place, time=DEFAULT_CACHE_EXPIRATION) @@ -262,8 +262,8 @@ def test_release_group_cache(self, release_group_fetch, cache_set, cache_get): # Test that first time data is fetched database is queried cache_get.assert_called_with(expected_key) - release_group_fetch.assert_called_with(mbid, includes=['artists', 'releases', - 'release-group-rels', 'url-rels', 'tags'], + release_group_fetch.assert_called_with(mbid, + includes=['artists', 'releases', 'release-group-rels', 'url-rels', 'tags'], unknown_entities_for_missing=True) cache_set.assert_called_with(key=expected_key, val=release_group, time=DEFAULT_CACHE_EXPIRATION) From e6b425530e5a76c940d83508590123d4bd1ecd82 Mon Sep 17 00:00:00 2001 From: Kartik Ohri Date: Sun, 22 Aug 2021 19:45:13 +0530 Subject: [PATCH 28/28] Update critiquebrainz/frontend/templates/review/entity/recording.html Co-authored-by: Jason --- critiquebrainz/frontend/templates/review/entity/recording.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/critiquebrainz/frontend/templates/review/entity/recording.html b/critiquebrainz/frontend/templates/review/entity/recording.html index 7543c966b..37290a2d0 100644 --- a/critiquebrainz/frontend/templates/review/entity/recording.html +++ b/critiquebrainz/frontend/templates/review/entity/recording.html @@ -10,7 +10,7 @@ {% block entity_title %}

    {% if recording %} - recording.name + {{ recording.name }} {% else %} {{ _('[Unknown recording]') }} {% endif %}