core: Don't allow TLIDs in queries, or integers
Handle this in tracklist.filter() which is the only API that allows number and/or TLIDs.
This commit is contained in:
parent
324bec1f4a
commit
97235f9441
@ -422,16 +422,17 @@ class TracklistController(object):
|
|||||||
:rtype: list of :class:`mopidy.models.TlTrack`
|
:rtype: list of :class:`mopidy.models.TlTrack`
|
||||||
"""
|
"""
|
||||||
criteria = criteria or kwargs
|
criteria = criteria or kwargs
|
||||||
|
tlids = criteria.pop('tlid', [])
|
||||||
validation.check_query(criteria)
|
validation.check_query(criteria)
|
||||||
|
validation.check_instances(tlids, int)
|
||||||
# TODO: deprecate kwargs
|
# TODO: deprecate kwargs
|
||||||
|
|
||||||
matches = self._tl_tracks
|
matches = self._tl_tracks
|
||||||
for (key, values) in criteria.items():
|
for (key, values) in criteria.items():
|
||||||
if key == 'tlid':
|
matches = [
|
||||||
matches = [ct for ct in matches if ct.tlid in values]
|
ct for ct in matches if getattr(ct.track, key) in values]
|
||||||
else:
|
if tlids:
|
||||||
matches = [
|
matches = [ct for ct in matches if ct.tlid in tlids]
|
||||||
ct for ct in matches if getattr(ct.track, key) in values]
|
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
def move(self, start, end, to_position):
|
def move(self, start, end, to_position):
|
||||||
|
|||||||
@ -9,7 +9,7 @@ PLAYBACK_STATES = {'paused', 'stopped', 'playing'}
|
|||||||
|
|
||||||
QUERY_FIELDS = {
|
QUERY_FIELDS = {
|
||||||
'uri', 'track_name', 'album', 'artist', 'albumartist', 'composer',
|
'uri', 'track_name', 'album', 'artist', 'albumartist', 'composer',
|
||||||
'performer', 'track_no', 'genre', 'date', 'comment', 'any', 'tlid', 'name'}
|
'performer', 'track_no', 'genre', 'date', 'comment', 'any', 'name'}
|
||||||
|
|
||||||
DISTINCT_FIELDS = {
|
DISTINCT_FIELDS = {
|
||||||
'artist', 'albumartist', 'album', 'composer', 'performer', 'date', 'genre'}
|
'artist', 'albumartist', 'album', 'composer', 'performer', 'date', 'genre'}
|
||||||
@ -62,9 +62,7 @@ def check_query(arg, list_values=True):
|
|||||||
# TODO: normalize name -> track_name
|
# TODO: normalize name -> track_name
|
||||||
# TODO: normalize value -> [value]
|
# TODO: normalize value -> [value]
|
||||||
# TODO: normalize blank -> [] or just remove field?
|
# TODO: normalize blank -> [] or just remove field?
|
||||||
# TODO: normalize int -> str or remove int support?
|
|
||||||
# TODO: remove list_values?
|
# TODO: remove list_values?
|
||||||
# TODO: don't allow for instance tlid field in all queries?
|
|
||||||
|
|
||||||
if not isinstance(arg, collections.Mapping):
|
if not isinstance(arg, collections.Mapping):
|
||||||
raise exceptions.ValidationError(
|
raise exceptions.ValidationError(
|
||||||
@ -83,10 +81,7 @@ def check_query(arg, list_values=True):
|
|||||||
|
|
||||||
|
|
||||||
def _check_query_value(key, arg, msg):
|
def _check_query_value(key, arg, msg):
|
||||||
if isinstance(arg, compat.string_types):
|
if not isinstance(arg, compat.string_types) or not arg.strip():
|
||||||
if not arg.strip():
|
|
||||||
raise exceptions.ValidationError(msg.format(arg=arg, key=key))
|
|
||||||
elif not isinstance(arg, (int, long)):
|
|
||||||
raise exceptions.ValidationError(msg.format(arg=arg, key=key))
|
raise exceptions.ValidationError(msg.format(arg=arg, key=key))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -98,7 +98,7 @@ def test_check_mapping_error_message():
|
|||||||
|
|
||||||
|
|
||||||
def test_check_query_invalid_fields():
|
def test_check_query_invalid_fields():
|
||||||
for value in 'wrong', 'bar', 'foo':
|
for value in 'wrong', 'bar', 'foo', 'tlid':
|
||||||
with raises(exceptions.ValidationError):
|
with raises(exceptions.ValidationError):
|
||||||
validation.check_query({value: []})
|
validation.check_query({value: []})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user