diff options
author | Michaël Ball <michael.ball@gmail.com> | 2019-06-30 11:12:05 +0100 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2019-06-30 11:12:05 +0100 |
commit | a87517a0b385f1a68dd80e7dabf7843955c95ab9 (patch) | |
tree | 696f1e2a45ab7c0db57ce562517790cb73247b53 /models/artist.py | |
parent | 1acbc1e85d6a0af47c236c48b8c5a1b504871d96 (diff) |
Style fixesfeature/pluggable-viewsdevelop
Diffstat (limited to 'models/artist.py')
-rw-r--r-- | models/artist.py | 63 |
1 files changed, 36 insertions, 27 deletions
diff --git a/models/artist.py b/models/artist.py index dada665..e91e66e 100644 --- a/models/artist.py +++ b/models/artist.py @@ -3,13 +3,12 @@ from models.base import BaseModel class Artist(BaseModel): - def __init__(self, db, id=None, **kwargs): self._db = db if id is not None: for row in self._db.execute("SELECT * FROM artist WHERE id = ?", - (id,)): + (id, )): for key in ["id", "name", "sortname", "musicbrainz_artistid"]: setattr(self, key, row[key]) else: @@ -22,13 +21,13 @@ class Artist(BaseModel): with self._db.conn: delete_artist = "DELETE FROM artist WHERE id = ?" - self._db.execute(delete_artist, (self.id,)) + self._db.execute(delete_artist, (self.id, )) delete_track_rel = "DELETE FROM artist_track WHERE artist_id = ?" - self._db.execute(delete_track_rel, (self.id,)) + self._db.execute(delete_track_rel, (self.id, )) delete_album_rel = "DELETE FROM album_artist WHERE artist_id = ?" - self._db.execute(delete_album_rel, (self.id,)) + self._db.execute(delete_album_rel, (self.id, )) return True @@ -47,14 +46,16 @@ class Artist(BaseModel): if not hasattr(self, "_tracks"): setattr(self, "_tracks", []) - for row in self._db.execute("SELECT track.* FROM track INNER " - "JOIN artist_track ON track.id = " - "artist_track.track_id WHERE " - "artist_id = ? ORDER BY name ASC", - (self.id,)): + for row in self._db.execute( + "SELECT track.* FROM track INNER " + "JOIN artist_track ON track.id = " + "artist_track.track_id WHERE " + "artist_id = ? ORDER BY name ASC", (self.id, )): - track = Track(id=row["id"], db=self._db, - tracknumber=row["tracknumber"], name=row["name"], + track = Track(id=row["id"], + db=self._db, + tracknumber=row["tracknumber"], + name=row["name"], grouping=row["grouping"], filename=row["filename"]) self._tracks.append(track) @@ -68,12 +69,14 @@ class Artist(BaseModel): if not hasattr(self, "_albums"): setattr(self, "_albums", []) - for row in self._db.execute("SELECT album.* FROM album INNER " - "JOIN album_artist ON album.id = " - "album_artist.album_id WHERE " - "artist_id = ? ORDER BY date ASC", - (self.id,)): - album = Album(id=row["id"], db=self._db, name=row["name"], + for row in self._db.execute( + "SELECT album.* FROM album INNER " + "JOIN album_artist ON album.id = " + "album_artist.album_id WHERE " + "artist_id = ? ORDER BY date ASC", (self.id, )): + album = Album(id=row["id"], + db=self._db, + name=row["name"], date=row["date"]) self._albums.append(album) @@ -126,15 +129,20 @@ class Artist(BaseModel): for row in result: artists.append( - Artist(id=row["id"], db=database, name=row["name"], + Artist(id=row["id"], + db=database, + name=row["name"], sortname=row["sortname"], - musicbrainz_artistid=row["musicbrainz_artistid"]) - ) + musicbrainz_artistid=row["musicbrainz_artistid"])) return artists @classmethod - def all(cls, database, order="sortname", direction="ASC", limit=None, + def all(cls, + database, + order="sortname", + direction="ASC", + limit=None, offset=None): artists = [] @@ -143,16 +151,17 @@ class Artist(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: artists.append( - Artist(id=row["id"], db=database, name=row["name"], + Artist(id=row["id"], + db=database, + name=row["name"], sortname=row["sortname"], - musicbrainz_artistid=row["musicbrainz_artistid"]) - ) + musicbrainz_artistid=row["musicbrainz_artistid"])) return artists |