summaryrefslogtreecommitdiff
path: root/models/album.py
diff options
context:
space:
mode:
Diffstat (limited to 'models/album.py')
-rw-r--r--models/album.py66
1 files changed, 39 insertions, 27 deletions
diff --git a/models/album.py b/models/album.py
index d55fb88..b7c3548 100644
--- a/models/album.py
+++ b/models/album.py
@@ -10,7 +10,7 @@ class Album(BaseModel):
if id is not None:
for row in self._db.execute("SELECT * FROM album WHERE id = ?",
- (id,)):
+ (id, )):
setattr(self, "id", id)
setattr(self, "name", row[1])
setattr(self, "date", row[2])
@@ -24,13 +24,13 @@ class Album(BaseModel):
with self._db.conn:
delete_album = "DELETE FROM album WHERE id = ?"
- self._db.execute(delete_album, (self.id,))
+ self._db.execute(delete_album, (self.id, ))
delete_track_rel = "DELETE FROM album_track WHERE album_id = ?"
- self._db.execute(delete_track_rel, (self.id,))
+ self._db.execute(delete_track_rel, (self.id, ))
delete_artist_rel = "DELETE FROM album_artist WHERE album_id = ?"
- self._db.execute(delete_artist_rel, (self.id,))
+ self._db.execute(delete_artist_rel, (self.id, ))
return True
@@ -49,13 +49,16 @@ class Album(BaseModel):
if not hasattr(self, "_artists"):
setattr(self, "_artists", [])
- for row in self._db.execute("SELECT artist.* FROM artist INNER "
- "JOIN album_artist ON artist.id = "
- "album_artist.artist_id WHERE "
- "album_id = ? ORDER BY name ASC",
- (self.id,)):
- artist = Artist(id=row[0], db=self._db, name=row[1],
- sortname=row[2], musicbrainz_artistid=row[3])
+ for row in self._db.execute(
+ "SELECT artist.* FROM artist INNER "
+ "JOIN album_artist ON artist.id = "
+ "album_artist.artist_id WHERE "
+ "album_id = ? ORDER BY name ASC", (self.id, )):
+ artist = Artist(id=row[0],
+ db=self._db,
+ name=row[1],
+ sortname=row[2],
+ musicbrainz_artistid=row[3])
self._artists.append(artist)
return self._artists
@@ -67,15 +70,18 @@ class Album(BaseModel):
if not hasattr(self, "_tracks"):
setattr(self, "_tracks", [])
- for row in self._db.execute("SELECT track.* FROM track INNER "
- "JOIN album_track ON track.id = "
- "album_track.track_id WHERE "
- "album_id = ? ORDER BY tracknumber "
- "ASC", (self.id,)):
+ for row in self._db.execute(
+ "SELECT track.* FROM track INNER "
+ "JOIN album_track ON track.id = "
+ "album_track.track_id WHERE "
+ "album_id = ? ORDER BY tracknumber "
+ "ASC", (self.id, )):
- track = Track(id=row["id"], db=self._db,
+ track = Track(id=row["id"],
+ db=self._db,
tracknumber=row["tracknumber"],
- name=row["name"], grouping=row["grouping"],
+ name=row["name"],
+ grouping=row["grouping"],
filename=row["filename"])
self._tracks.append(track)
@@ -135,14 +141,19 @@ class Album(BaseModel):
for row in result:
albums.append(
- Album(id=row["id"], db=database, name=row["name"],
- date=row["date"])
- )
+ Album(id=row["id"],
+ db=database,
+ name=row["name"],
+ date=row["date"]))
return albums
@classmethod
- def all(cls, database, order="album.id", direction="ASC", limit=None,
+ def all(cls,
+ database,
+ order="album.id",
+ direction="ASC",
+ limit=None,
offset=None):
albums = []
@@ -153,15 +164,16 @@ class Album(BaseModel):
direction)
if limit is not None and offset is not None:
- select_string = " ".join((select_string,
- "LIMIT %s OFFSET %s" % (limit, offset)))
+ select_string = " ".join(
+ (select_string, "LIMIT %s OFFSET %s" % (limit, offset)))
result = database.execute(select_string)
for row in result:
albums.append(
- Album(id=row["id"], db=database, name=row["name"],
- date=row["date"])
- )
+ Album(id=row["id"],
+ db=database,
+ name=row["name"],
+ date=row["date"]))
return albums