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`
|
||||
"""
|
||||
criteria = criteria or kwargs
|
||||
tlids = criteria.pop('tlid', [])
|
||||
validation.check_query(criteria)
|
||||
validation.check_instances(tlids, int)
|
||||
# TODO: deprecate kwargs
|
||||
|
||||
matches = self._tl_tracks
|
||||
for (key, values) in criteria.items():
|
||||
if key == 'tlid':
|
||||
matches = [ct for ct in matches if ct.tlid in values]
|
||||
else:
|
||||
matches = [
|
||||
ct for ct in matches if getattr(ct.track, key) in values]
|
||||
matches = [
|
||||
ct for ct in matches if getattr(ct.track, key) in values]
|
||||
if tlids:
|
||||
matches = [ct for ct in matches if ct.tlid in tlids]
|
||||
return matches
|
||||
|
||||
def move(self, start, end, to_position):
|
||||
|
||||
@ -9,7 +9,7 @@ PLAYBACK_STATES = {'paused', 'stopped', 'playing'}
|
||||
|
||||
QUERY_FIELDS = {
|
||||
'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 = {
|
||||
'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 value -> [value]
|
||||
# TODO: normalize blank -> [] or just remove field?
|
||||
# TODO: normalize int -> str or remove int support?
|
||||
# TODO: remove list_values?
|
||||
# TODO: don't allow for instance tlid field in all queries?
|
||||
|
||||
if not isinstance(arg, collections.Mapping):
|
||||
raise exceptions.ValidationError(
|
||||
@ -83,10 +81,7 @@ def check_query(arg, list_values=True):
|
||||
|
||||
|
||||
def _check_query_value(key, arg, msg):
|
||||
if isinstance(arg, compat.string_types):
|
||||
if not arg.strip():
|
||||
raise exceptions.ValidationError(msg.format(arg=arg, key=key))
|
||||
elif not isinstance(arg, (int, long)):
|
||||
if not isinstance(arg, compat.string_types) or not arg.strip():
|
||||
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():
|
||||
for value in 'wrong', 'bar', 'foo':
|
||||
for value in 'wrong', 'bar', 'foo', 'tlid':
|
||||
with raises(exceptions.ValidationError):
|
||||
validation.check_query({value: []})
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user