diff --git a/mopidy/core/playlists.py b/mopidy/core/playlists.py index a430e3ff..b470fa56 100644 --- a/mopidy/core/playlists.py +++ b/mopidy/core/playlists.py @@ -176,7 +176,8 @@ class PlaylistsController(object): deprecation.warn('core.playlists.filter') criteria = criteria or kwargs - validation.check_query(criteria, list_values=False) + validation.check_query( + criteria, validation.PLAYLIST_FIELDS, list_values=False) # TODO: stop using self playlists matches = self.playlists diff --git a/mopidy/core/tracklist.py b/mopidy/core/tracklist.py index 54143578..21c6d86a 100644 --- a/mopidy/core/tracklist.py +++ b/mopidy/core/tracklist.py @@ -423,9 +423,10 @@ class TracklistController(object): """ criteria = criteria or kwargs tlids = criteria.pop('tlid', []) - validation.check_query(criteria) + validation.check_query(criteria, validation.TRACKLIST_FIELDS) validation.check_instances(tlids, int) # TODO: deprecate kwargs + # TODO: id=[1, 2, 3] filtering can't possibly be working matches = self._tl_tracks for (key, values) in criteria.items(): diff --git a/mopidy/utils/validation.py b/mopidy/utils/validation.py index c158f340..4897f513 100644 --- a/mopidy/utils/validation.py +++ b/mopidy/utils/validation.py @@ -7,9 +7,14 @@ from mopidy import compat, exceptions PLAYBACK_STATES = {'paused', 'stopped', 'playing'} -QUERY_FIELDS = { +SEARCH_FIELDS = { 'uri', 'track_name', 'album', 'artist', 'albumartist', 'composer', - 'performer', 'track_no', 'genre', 'date', 'comment', 'any', 'name'} + 'performer', 'track_no', 'genre', 'date', 'comment', 'any'} + +PLAYLIST_FIELDS = {'uri', 'name'} # TODO: add length and last_modified? + +TRACKLIST_FIELDS = { # TODO: add bitrate, length, disc_no, track_no, modified? + 'uri', 'name', 'genre', 'date', 'comment', 'musicbrainz_id'} DISTINCT_FIELDS = { 'artist', 'albumartist', 'album', 'composer', 'performer', 'date', 'genre'} @@ -58,7 +63,7 @@ def check_integer(arg, min=None, max=None): 'Expected number smaller or equal to %d, not %r' % (max, arg)) -def check_query(arg, list_values=True): +def check_query(arg, fields=SEARCH_FIELDS, list_values=True): # TODO: normalize name -> track_name # TODO: normalize value -> [value] # TODO: normalize blank -> [] or just remove field? @@ -69,8 +74,8 @@ def check_query(arg, list_values=True): 'Expected a query dictionary, not {arg!r}'.format(arg=arg)) for key, value in arg.items(): - check_choice(key, QUERY_FIELDS, msg='Expected query field to be one ' - 'of {choices}, not {arg!r}') + check_choice(key, fields, msg='Expected query field to be one of ' + '{choices}, not {arg!r}') if list_values: msg = 'Expected "{key}" to be list of strings, not {arg!r}' _check_iterable(value, msg, key=key)