Skip to content

Commit

Permalink
Implemented the searching of labels
Browse files Browse the repository at this point in the history
  • Loading branch information
spellew committed Aug 8, 2019
1 parent 2cd202d commit 0558b7c
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 2 deletions.
2 changes: 2 additions & 0 deletions critiquebrainz/frontend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def create_app(debug=None, config_path=None):
from critiquebrainz.frontend.views.review import review_bp
from critiquebrainz.frontend.views.search import search_bp
from critiquebrainz.frontend.views.artist import artist_bp
from critiquebrainz.frontend.views.label import label_bp
from critiquebrainz.frontend.views.release_group import release_group_bp
from critiquebrainz.frontend.views.release import release_bp
from critiquebrainz.frontend.views.event import event_bp
Expand All @@ -152,6 +153,7 @@ def create_app(debug=None, config_path=None):
app.register_blueprint(review_bp, url_prefix='/review')
app.register_blueprint(search_bp, url_prefix='/search')
app.register_blueprint(artist_bp, url_prefix='/artist')
app.register_blueprint(label_bp, url_prefix='/label')
app.register_blueprint(release_group_bp, url_prefix='/release-group')
app.register_blueprint(release_bp, url_prefix='/release')
app.register_blueprint(event_bp, url_prefix='/event')
Expand Down
6 changes: 6 additions & 0 deletions critiquebrainz/frontend/external/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ def search_places(query='', limit=None, offset=None):
"""Search for places."""
api_resp = musicbrainzngs.search_places(query=query, limit=limit, offset=offset)
return api_resp.get('place-count'), api_resp.get('place-list')


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')
1 change: 1 addition & 0 deletions critiquebrainz/frontend/templates/label/entity.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends 'base.html' %}
3 changes: 2 additions & 1 deletion critiquebrainz/frontend/templates/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@
<div class="form-group">
<select id="type-selector" name="type" class="form-control input-sm">
<option value="artist">{{ _('Artist') }}</option>
<option value="release-group">{{ _('Release group') }}</option>
<option value="label">{{ _('Label') }}</option>
<option value="event">{{ _('Event') }}</option>
<option value="place">{{ _('Place') }}</option>
<option value="release-group">{{ _('Release group') }}</option>
</select>
</div>
<button type="submit" class="btn input-sm"><span class="glyphicon glyphicon-search"></span></button>
Expand Down
7 changes: 7 additions & 0 deletions critiquebrainz/frontend/templates/search/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ <h3>{{ _('Search') }}</h3>
<option value="release-group" {% if type=="release-group" %}selected="selected"{% endif %}>{{ _('Release group') }}</option>
<option value="artist" {% if type=="artist" %}selected="selected"{% endif %}>{{ _('Artist') }}</option>
<option value="event" {% if type=="event" %}selected="selected"{% endif %}>{{ _('Event') }}</option>
<option value="label" {% if type=="label" %}selected="selected"{% endif %}>{{ _('Label') }}</option>
<option value="place" {% if type=="place" %}selected="selected"{% endif %}>{{ _('Place') }}</option>
</select>
</div>
Expand Down Expand Up @@ -70,6 +71,12 @@ <h3>{{ _('Search') }}</h3>
<th>{{ _('Artist') }}</th>
<th>{{ _('Type') }}</th>
</tr>
{% elif type=="label" %}
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Type') }}</th>
<th>{{ _('Country') }}</th>
</tr>
{% endif %}
</thead>
<tbody id="results">{% include 'search/results.html' %}</tbody>
Expand Down
13 changes: 13 additions & 0 deletions critiquebrainz/frontend/templates/search/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,18 @@
</td>
</tr>

{% elif type=="label" %}
<tr>
<td>
<a href="{{ url_for('label.entity', id=result.id) }}">{{ result['name'] }}</a>
</td>
<td>
{{ result['type'] or '-' }}
</td>
<td>
{{ result['country'] or '-' }}
</td>
</tr>

{% endif %}
{% endfor %}
30 changes: 30 additions & 0 deletions critiquebrainz/frontend/templates/search/selector.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
<li {% if type=="place" %}class="active"{% endif %}>
<a href="#place" data-toggle="tab">Place</a>
</li>
<li {% if type=="label" %}class="active"{% endif %}>
<a href="#label" data-toggle="tab">{{ _('Label') }}</a>
</li>
</ul>

<div class="tab-content">
Expand Down Expand Up @@ -101,6 +104,26 @@ <h3>{{ _('Place selection') }}</h3>
</form>
</div>

<div id="label" class="tab-pane {% if type=="label" %}active{% endif %}">
<h3>{{ _('Label selection') }}</h3>
<form method="GET" class="form-horizontal" role="form">
<div class="form-group">
<label for="input-release-group" class="col-sm-2 control-label">{{ _('Label') }}</label>
<div class="col-sm-4">
<input id="input-release-group" class="form-control" name="label" type="text"
value="{{ request.args.get('label', default='') }}">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">{{ _('Search') }}</button>
</div>
</div>
<input type="hidden" name="next" value="{{ next }}" />
<input type="hidden" name="type" value="label" />
</form>
</div>

</div>
</div>

Expand All @@ -109,6 +132,7 @@ <h3>{{ _('Place selection') }}</h3>
or request.args.get('release_group', default=False)
or request.args.get('event', default=False)
or request.args.get('place', default=False)
or request.args.get('label', default=False)
%}
<hr />
{% if not results %}
Expand Down Expand Up @@ -146,6 +170,12 @@ <h3>{{ _('Place selection') }}</h3>
<th>{{ _('Location') }}</th>
<th></th>
</tr>
{% elif type=="label" %}
<tr>
<th>{{ _('Name') }}</th>
<th>{{ _('Type') }}</th>
<th>{{ _('Country') }}</th>
</tr>
{% endif %}
</thead>
<tbody id="results">{% include 'search/selector_results.html' %}</tbody>
Expand Down
16 changes: 16 additions & 0 deletions critiquebrainz/frontend/templates/search/selector_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,21 @@
</td>
</tr>

{% elif type=="label" %}
<tr>
<td>
<a href="{{ url_for('label.entity', id=result.id) }}" target="_blank">{{ result['name'] }}</a>
</td>
<td>
{{ result['type'] or '-' }}
</td>
<td>
{{ result['country'] or '-' }}
</td>
<td>
<input type="radio" name="label" value="{{ result['id'] }}">
</td>
</tr>

{% endif %}
{% endfor %}
41 changes: 41 additions & 0 deletions critiquebrainz/frontend/views/label.py
Original file line number Diff line number Diff line change
@@ -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.label as mb_label
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


label_bp = Blueprint('label', __name__)


@label_bp.route('/<uuid:id>')
def entity(id):
id = str(id)
try:
label = mb_label.get_label_by_id(id)
except mb_exceptions.NoDataFoundException:
raise NotFound(gettext("Sorry, we couldn't find a label with that MusicBrainz ID."))

return render_template('label/entity.html', id=label['id'], label=label)
10 changes: 9 additions & 1 deletion critiquebrainz/frontend/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def search_wrapper(query, type, offset=None):
count, results = musicbrainz.search_places(query, limit=RESULTS_LIMIT, offset=offset)
elif type == "release-group":
count, results = musicbrainz.search_release_groups(query, limit=RESULTS_LIMIT, offset=offset)
elif type == "label":
count, results = musicbrainz.search_labels(query, limit=RESULTS_LIMIT, offset=offset)
else:
count, results = 0, []
else:
Expand Down Expand Up @@ -46,6 +48,7 @@ def more():
def selector():
release_group = request.args.get('release_group')
artist = request.args.get('artist')
label = request.args.get('label')
event = request.args.get('event')
place = request.args.get('place')
type = request.args.get('type')
Expand All @@ -56,6 +59,8 @@ def selector():
count, results = musicbrainz.search_release_groups(release_group, limit=RESULTS_LIMIT)
elif artist:
count, results = musicbrainz.search_artists(artist, limit=RESULTS_LIMIT)
elif label:
count, results = musicbrainz.search_labels(label, limit=RESULTS_LIMIT)
elif event:
count, results = musicbrainz.search_events(event, limit=RESULTS_LIMIT)
elif place:
Expand All @@ -65,13 +70,14 @@ 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,
place=place)
label=label, place=place)


@search_bp.route('/selector/more')
def selector_more():
artist = request.args.get('artist')
release_group = request.args.get('release_group')
label = request.args.get('label')
event = request.args.get('event')
place = request.args.get('place')
type = request.args.get('type')
Expand All @@ -82,6 +88,8 @@ def selector_more():
limit=RESULTS_LIMIT, offset=offset)
elif type == 'artist':
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 == 'event':
count, results = musicbrainz.search_events(event, limit=RESULTS_LIMIT, offset=offset)
elif type == 'place':
Expand Down

0 comments on commit 0558b7c

Please sign in to comment.