Reordered functions in model.Playlists
This commit is contained in:
parent
403313c0dd
commit
52d48406ea
136
app/model.py
136
app/model.py
@ -166,6 +166,64 @@ class Playlists(Base):
|
||||
def __repr__(self):
|
||||
return (f"<Playlist(id={self.id}, name={self.name}>")
|
||||
|
||||
def add_track(self, session, track, row=None):
|
||||
"""
|
||||
Add track to playlist at given row.
|
||||
If row=None, add to end of playlist
|
||||
"""
|
||||
|
||||
if not row:
|
||||
row = PlaylistTracks.new_row(session, self.id)
|
||||
|
||||
glue = PlaylistTracks(row=row)
|
||||
glue.track_id = track.id
|
||||
self.tracks.append(glue)
|
||||
session.commit()
|
||||
|
||||
def close(self, session):
|
||||
"Record playlist as no longer loaded"
|
||||
|
||||
self.loaded = False
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def get_all_closed_playlists(session):
|
||||
"Returns a list of all playlists not currently open"
|
||||
|
||||
return (
|
||||
session.query(Playlists)
|
||||
.filter(
|
||||
(Playlists.loaded == False) | # noqa E712
|
||||
(Playlists.loaded == None)
|
||||
)
|
||||
.order_by(Playlists.last_used.desc())
|
||||
).all()
|
||||
|
||||
@staticmethod
|
||||
def get_all_playlists(session):
|
||||
"Returns a list of all playlists"
|
||||
|
||||
return session.query(Playlists).all()
|
||||
|
||||
@staticmethod
|
||||
def get_last_used(session):
|
||||
"""
|
||||
Return a list of playlists marked "loaded", ordered by loaded date.
|
||||
"""
|
||||
|
||||
return (
|
||||
session.query(Playlists)
|
||||
.filter(Playlists.loaded == True) # noqa E712
|
||||
.order_by(Playlists.last_used.desc())
|
||||
).all()
|
||||
|
||||
def get_notes(self):
|
||||
return [a.note for a in self.notes]
|
||||
|
||||
def get_tracks(self):
|
||||
return [a.tracks for a in self.tracks]
|
||||
|
||||
@staticmethod
|
||||
def new(session, name):
|
||||
DEBUG(f"Playlists.new(name={name})")
|
||||
@ -186,77 +244,6 @@ class Playlists(Base):
|
||||
|
||||
return p
|
||||
|
||||
def close(self, session):
|
||||
"Record playlist as no longer loaded"
|
||||
|
||||
self.loaded = False
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def get_last_used(session):
|
||||
"""
|
||||
Return a list of playlists marked "loaded", ordered by loaded date.
|
||||
"""
|
||||
|
||||
return (
|
||||
session.query(Playlists)
|
||||
.filter(Playlists.loaded == True) # noqa E712
|
||||
.order_by(Playlists.last_used.desc())
|
||||
).all()
|
||||
|
||||
@staticmethod
|
||||
def get_all_playlists(session):
|
||||
"Returns a list of all playlists"
|
||||
|
||||
return session.query(Playlists).all()
|
||||
|
||||
@staticmethod
|
||||
def get_all_closed_playlists(session):
|
||||
"Returns a list of all playlists not currently open"
|
||||
|
||||
return (
|
||||
session.query(Playlists)
|
||||
.filter(
|
||||
(Playlists.loaded == False) | # noqa E712
|
||||
(Playlists.loaded == None)
|
||||
)
|
||||
.order_by(Playlists.last_used.desc())
|
||||
).all()
|
||||
|
||||
# Not currently used 1 June 2021
|
||||
# @staticmethod
|
||||
# def get_name(session, plid):
|
||||
# """
|
||||
# Return name of playlist with id 'plid'
|
||||
# """
|
||||
|
||||
# return (
|
||||
# session.query(Playlists.name)
|
||||
# .filter(Playlists.id == plid)
|
||||
# ).one()[0]
|
||||
|
||||
def add_track(self, session, track, row=None):
|
||||
"""
|
||||
Add track to playlist at given row.
|
||||
If row=None, add to end of playlist
|
||||
"""
|
||||
|
||||
if not row:
|
||||
row = PlaylistTracks.new_row(session, self.id)
|
||||
|
||||
glue = PlaylistTracks(row=row)
|
||||
glue.track_id = track.id
|
||||
self.tracks.append(glue)
|
||||
session.commit()
|
||||
|
||||
def get_notes(self):
|
||||
return [a.note for a in self.notes]
|
||||
|
||||
def get_tracks(self):
|
||||
return [a.tracks for a in self.tracks]
|
||||
|
||||
|
||||
class PlaylistTracks(Base):
|
||||
__tablename__ = 'playlisttracks'
|
||||
|
||||
@ -267,13 +254,6 @@ class PlaylistTracks(Base):
|
||||
tracks = relationship("Tracks", back_populates="playlists")
|
||||
playlists = relationship("Playlists", back_populates="tracks")
|
||||
|
||||
@staticmethod
|
||||
def new_row(session, playlist_id):
|
||||
"Return row number > largest existing row number"
|
||||
|
||||
last_row = session.query(func.max(PlaylistTracks.row)).one()[0]
|
||||
return last_row + 1
|
||||
|
||||
@staticmethod
|
||||
def add_track(session, playlist_id, track_id, row):
|
||||
DEBUG(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user