core: Add 'include_tracks' argument to 'get_playlists()'
Conflicts: docs/changes.rst
This commit is contained in:
parent
5c6a2e02ba
commit
04b24b4a37
@ -24,6 +24,15 @@ v0.11.2 (UNRELEASED)
|
||||
|
||||
- Make ``mopidy-scan`` support symlinks.
|
||||
|
||||
**Core API**
|
||||
|
||||
- :meth:`mopidy.core.PlaylistsController.get_playlists` now accepts an argument
|
||||
``include_tracks``. This defaults to :class:`True`, which has the same old
|
||||
behavior. If set to :class:`False`, the tracks are stripped from the
|
||||
playlists before they are returned. This can be used to limit the amount of
|
||||
data returned if the response is to be passed out of the application, e.g. to
|
||||
a web client. (Fixes: :issue:`297`)
|
||||
|
||||
|
||||
v0.11.1 (2012-12-24)
|
||||
====================
|
||||
|
||||
@ -15,11 +15,14 @@ class PlaylistsController(object):
|
||||
self.backends = backends
|
||||
self.core = core
|
||||
|
||||
def get_playlists(self):
|
||||
def get_playlists(self, include_tracks=True):
|
||||
futures = [
|
||||
b.playlists.playlists for b in self.backends.with_playlists]
|
||||
results = pykka.get_all(futures)
|
||||
return list(itertools.chain(*results))
|
||||
playlists = list(itertools.chain(*results))
|
||||
if not include_tracks:
|
||||
playlists = [p.copy(tracks=[]) for p in playlists]
|
||||
return playlists
|
||||
|
||||
playlists = property(get_playlists)
|
||||
"""
|
||||
|
||||
@ -46,6 +46,22 @@ class PlaylistsTest(unittest.TestCase):
|
||||
self.assertIn(self.pl2a, result)
|
||||
self.assertIn(self.pl2b, result)
|
||||
|
||||
def test_get_playlists_includes_tracks_by_default(self):
|
||||
result = self.core.playlists.get_playlists()
|
||||
|
||||
self.assertEqual(result[0].name, 'A')
|
||||
self.assertEqual(len(result[0].tracks), 1)
|
||||
self.assertEqual(result[1].name, 'B')
|
||||
self.assertEqual(len(result[1].tracks), 1)
|
||||
|
||||
def test_get_playlist_can_strip_tracks_from_returned_playlists(self):
|
||||
result = self.core.playlists.get_playlists(include_tracks=False)
|
||||
|
||||
self.assertEqual(result[0].name, 'A')
|
||||
self.assertEqual(len(result[0].tracks), 0)
|
||||
self.assertEqual(result[1].name, 'B')
|
||||
self.assertEqual(len(result[1].tracks), 0)
|
||||
|
||||
def test_create_without_uri_scheme_uses_first_backend(self):
|
||||
playlist = Playlist()
|
||||
self.sp1.create().get.return_value = playlist
|
||||
|
||||
@ -603,7 +603,7 @@ class JsonRpcInspectorTest(JsonRpcTestBase):
|
||||
|
||||
self.assertIn('core.playlists.get_playlists', methods)
|
||||
self.assertEquals(
|
||||
len(methods['core.playlists.get_playlists']['params']), 0)
|
||||
len(methods['core.playlists.get_playlists']['params']), 1)
|
||||
|
||||
self.assertIn('core.tracklist.filter', methods.keys())
|
||||
self.assertEquals(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user