From fbb7cc5719e863bd279a48dc4451a74f7fc4851a Mon Sep 17 00:00:00 2001 From: Ansh Goyal Date: Wed, 27 Jul 2022 19:30:04 +0000 Subject: [PATCH] feat: Allow sorting reviews by MB - BB --- critiquebrainz/db/review.py | 26 ++++++++++++-- .../frontend/templates/review/browse.html | 35 ++++++++++++------- critiquebrainz/frontend/views/review.py | 4 +-- 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/critiquebrainz/db/review.py b/critiquebrainz/db/review.py index a3ab91b31..9b2cbe8d0 100644 --- a/critiquebrainz/db/review.py +++ b/critiquebrainz/db/review.py @@ -33,6 +33,21 @@ "bb_literary_work" ] +MUSICBRAINZ_ENTITY_TYPES = [ + "event", + "place", + "release_group", + "work", + "artist", + "label", + "recording" +] + +BOOKBRAINZ_ENTITY_TYPES = [ + "bb_edition_group", + "bb_literary_work" +] + supported_languages = [] for lang in list(pycountry.languages): if 'iso639_1_code' in dir(lang): @@ -418,8 +433,15 @@ def get_reviews_list(connection, *, inc_drafts=False, inc_hidden=False, entity_i filter_data["entity_id"] = entity_id if entity_type is not None: - filters.append("entity_type = :entity_type") - filter_data["entity_type"] = entity_type + if entity_type == 'musicbrainz': + filters.append("entity_type in :entity_type") + filter_data["entity_type"] = tuple(MUSICBRAINZ_ENTITY_TYPES) + elif entity_type == 'bookbrainz': + filters.append("entity_type in :entity_type") + filter_data["entity_type"] = tuple(BOOKBRAINZ_ENTITY_TYPES) + else: + filters.append("entity_type = :entity_type") + filter_data["entity_type"] = entity_type if license_id is not None: filters.append("license_id = :license_id") diff --git a/critiquebrainz/frontend/templates/review/browse.html b/critiquebrainz/frontend/templates/review/browse.html index 0d95d5807..39a49df22 100644 --- a/critiquebrainz/frontend/templates/review/browse.html +++ b/critiquebrainz/frontend/templates/review/browse.html @@ -9,6 +9,22 @@

{{ _('Reviews') }}

+ +
diff --git a/critiquebrainz/frontend/views/review.py b/critiquebrainz/frontend/views/review.py index c4c2e68da..0f47c1e24 100644 --- a/critiquebrainz/frontend/views/review.py +++ b/critiquebrainz/frontend/views/review.py @@ -41,7 +41,7 @@ def get_review_or_404(review_id): valid_browse_sort = ['published_on', 'popularity'] valid_browse_sort_order = ['asc', 'desc'] - +valid_entity_types = ENTITY_TYPES + ['musicbrainz', 'bookbrainz'] @review_bp.route('/') def browse(): @@ -58,7 +58,7 @@ def browse(): ('published_on', 'asc'): gettext('Oldest') } - if entity_type and entity_type not in ENTITY_TYPES: + if entity_type and entity_type not in valid_entity_types: raise BadRequest("Not a valid entity type.") if sort not in valid_browse_sort: