From dba2a9b6624cecfa976b796f46933bf3a7f8dd12 Mon Sep 17 00:00:00 2001 From: spl0k Date: Wed, 26 Feb 2014 22:41:59 +0100 Subject: [PATCH] Fix random with no tracks Closes #10 --- api/albums_songs.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api/albums_songs.py b/api/albums_songs.py index 8bdfe42..75e996f 100644 --- a/api/albums_songs.py +++ b/api/albums_songs.py @@ -60,6 +60,10 @@ def album_list(): if ltype == 'random': albums = [] count = query.count() + + if not count: + return request.formatter({ 'albumList': {} }) + for _ in xrange(size): x = random.choice(xrange(count)) albums.append(query.offset(x).limit(1).one()) @@ -106,6 +110,10 @@ def album_list_id3(): if ltype == 'random': albums = [] count = query.count() + + if not count: + return request.formatter({ 'albumList2': {} }) + for _ in xrange(size): x = random.choice(xrange(count)) albums.append(query.offset(x).limit(1).one())