Add lookup by CPID to CurrentPlaylistController.get()
This commit is contained in:
parent
454d304953
commit
8c3d3603e2
@ -136,6 +136,8 @@ class BaseCurrentPlaylistController(object):
|
||||
|
||||
Examples::
|
||||
|
||||
get(cpid=7) # Returns track with CPID 7
|
||||
# (current playlist ID)
|
||||
get(id=1) # Returns track with ID 1
|
||||
get(uri='xyz') # Returns track with URI 'xyz'
|
||||
get(id=1, uri='xyz') # Returns track with ID 1 and URI 'xyz'
|
||||
@ -144,11 +146,15 @@ class BaseCurrentPlaylistController(object):
|
||||
:type criteria: dict
|
||||
:rtype: :class:`mopidy.models.Track`
|
||||
"""
|
||||
matches = self.tracks
|
||||
matches = self._cp_tracks
|
||||
for (key, value) in criteria.iteritems():
|
||||
matches = filter(lambda t: getattr(t, key) == value, matches)
|
||||
if key == 'cpid':
|
||||
matches = filter(lambda ct: ct[0] == value, matches)
|
||||
else:
|
||||
matches = filter(lambda ct: getattr(ct[1], key) == value,
|
||||
matches)
|
||||
if len(matches) == 1:
|
||||
return matches[0]
|
||||
return matches[0][1] # The track part of the only match
|
||||
criteria_string = ', '.join(
|
||||
['%s=%s' % (k, v) for (k, v) in criteria.iteritems()])
|
||||
if len(matches) == 0:
|
||||
|
||||
@ -61,6 +61,12 @@ class BaseCurrentPlaylistControllerTest(object):
|
||||
for track in self.controller.tracks:
|
||||
self.assertNotEqual(None, track.id)
|
||||
|
||||
@populate_playlist
|
||||
def test_get_by_cpid(self):
|
||||
track = self.controller.tracks[1]
|
||||
cpid = self.controller._cp_tracks[1][0] # XXX Messing in internals
|
||||
self.assertEqual(track, self.controller.get(cpid=cpid))
|
||||
|
||||
@populate_playlist
|
||||
def test_get_by_id(self):
|
||||
track = self.controller.tracks[1]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user