db: Add a function so Albums can list their Discs
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
bbb248f665
commit
00e15c8422
|
@ -10,9 +10,10 @@
|
|||
# | (artistid, name) -> albumid |
|
||||
# +-----------------------------+
|
||||
from gi.repository import GObject
|
||||
from . import artist
|
||||
from . import disc
|
||||
from . import execute
|
||||
from . import objects
|
||||
from . import artist
|
||||
|
||||
class Album(objects.Tag):
|
||||
def do_get_column(self, column):
|
||||
|
@ -23,6 +24,11 @@ class Album(objects.Tag):
|
|||
def artist(self):
|
||||
return artist.Artist(self.get_column("artistid"))
|
||||
|
||||
def discs(self):
|
||||
cursor = execute(f"SELECT discid FROM discs "
|
||||
"WHERE albumid=?", [ self.rowid ])
|
||||
return [ disc.Disc(row["discid"]) for row in cursor.fetchall() ]
|
||||
|
||||
|
||||
class AlbumTable(objects.Table):
|
||||
def __init__(self):
|
||||
|
|
|
@ -51,3 +51,10 @@ class TestAlbumTable(unittest.TestCase):
|
|||
album = db.album.Table.insert(artist, "Test Album")
|
||||
self.assertEqual(db.album.Table.lookup(artist, "Test Album"), album)
|
||||
self.assertIsNone(db.album.Table.lookup(artist, "none"))
|
||||
|
||||
def test_album_discs(self):
|
||||
artist = db.artist.Table.find("Test Artist", "Test Sort")
|
||||
album = db.album.Table.find(artist, "Test Album")
|
||||
disc1 = db.disc.Table.find(album, 1, None)
|
||||
disc2 = db.disc.Table.find(album, 2, None)
|
||||
self.assertEqual(album.discs(), [ disc1, disc2 ])
|
||||
|
|
Loading…
Reference in New Issue