Update db correctly when opening/closing playlists.
Ensures that open playlist dialog box lists playlists in last-used order.
This commit is contained in:
parent
441c47bdc2
commit
1ea2f7b531
13
app/model.py
13
app/model.py
@ -270,17 +270,14 @@ class Playlists(Base):
|
||||
session.commit()
|
||||
return playlist
|
||||
|
||||
@staticmethod
|
||||
def open(session, plid):
|
||||
"Record playlist as loaded and used now"
|
||||
def open(self, session):
|
||||
"Mark playlist as loaded and used now"
|
||||
|
||||
p = session.query(Playlists).filter(Playlists.id == plid).one()
|
||||
p.loaded = True
|
||||
p.last_used = datetime.now()
|
||||
self.loaded = True
|
||||
self.last_used = datetime.now()
|
||||
session.add(self)
|
||||
session.commit()
|
||||
|
||||
return p
|
||||
|
||||
|
||||
class PlaylistTracks(Base):
|
||||
__tablename__ = 'playlisttracks'
|
||||
|
||||
@ -236,7 +236,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
# It's OK to close this playlist so remove from open playlist list
|
||||
with Session() as session:
|
||||
playlist_db = session.query(Playlists).filter(
|
||||
Playlists.id == self.visible_playlist_tab().id).one()
|
||||
Playlists.id == self.tabPlaylist.widget(index).id).one()
|
||||
playlist_db.close(session)
|
||||
# Close regardless of tab type
|
||||
self.tabPlaylist.removeTab(index)
|
||||
@ -413,6 +413,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
|
||||
playlist_tab = PlaylistTab(self)
|
||||
playlist_db.open(session)
|
||||
playlist_tab.populate(session, playlist_db)
|
||||
idx = self.tabPlaylist.addTab(playlist_tab, playlist_db.name)
|
||||
self.tabPlaylist.setCurrentIndex(idx)
|
||||
@ -554,7 +555,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
dlg = SelectPlaylistDialog(self, playlist_dbs=playlist_dbs)
|
||||
dlg.exec()
|
||||
if dlg.plid:
|
||||
playlist_db = Playlists.open(session, dlg.plid)
|
||||
playlist_db = Playlists.get_playlist(session, dlg.plid)
|
||||
self.load_playlist(session, playlist_db)
|
||||
|
||||
def select_next_row(self):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user