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()
|
session.commit()
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
@staticmethod
|
def open(self, session):
|
||||||
def open(session, plid):
|
"Mark playlist as loaded and used now"
|
||||||
"Record playlist as loaded and used now"
|
|
||||||
|
|
||||||
p = session.query(Playlists).filter(Playlists.id == plid).one()
|
self.loaded = True
|
||||||
p.loaded = True
|
self.last_used = datetime.now()
|
||||||
p.last_used = datetime.now()
|
session.add(self)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
return p
|
|
||||||
|
|
||||||
|
|
||||||
class PlaylistTracks(Base):
|
class PlaylistTracks(Base):
|
||||||
__tablename__ = 'playlisttracks'
|
__tablename__ = 'playlisttracks'
|
||||||
|
|||||||
@ -236,7 +236,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
# It's OK to close this playlist so remove from open playlist list
|
# It's OK to close this playlist so remove from open playlist list
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
playlist_db = session.query(Playlists).filter(
|
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)
|
playlist_db.close(session)
|
||||||
# Close regardless of tab type
|
# Close regardless of tab type
|
||||||
self.tabPlaylist.removeTab(index)
|
self.tabPlaylist.removeTab(index)
|
||||||
@ -413,6 +413,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
playlist_tab = PlaylistTab(self)
|
playlist_tab = PlaylistTab(self)
|
||||||
|
playlist_db.open(session)
|
||||||
playlist_tab.populate(session, playlist_db)
|
playlist_tab.populate(session, playlist_db)
|
||||||
idx = self.tabPlaylist.addTab(playlist_tab, playlist_db.name)
|
idx = self.tabPlaylist.addTab(playlist_tab, playlist_db.name)
|
||||||
self.tabPlaylist.setCurrentIndex(idx)
|
self.tabPlaylist.setCurrentIndex(idx)
|
||||||
@ -554,7 +555,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
dlg = SelectPlaylistDialog(self, playlist_dbs=playlist_dbs)
|
dlg = SelectPlaylistDialog(self, playlist_dbs=playlist_dbs)
|
||||||
dlg.exec()
|
dlg.exec()
|
||||||
if dlg.plid:
|
if dlg.plid:
|
||||||
playlist_db = Playlists.open(session, dlg.plid)
|
playlist_db = Playlists.get_playlist(session, dlg.plid)
|
||||||
self.load_playlist(session, playlist_db)
|
self.load_playlist(session, playlist_db)
|
||||||
|
|
||||||
def select_next_row(self):
|
def select_next_row(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user