From f1796451ae97c6406ef0b1fbb2a32a6e4710fae4 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Sat, 13 Aug 2022 11:06:52 +0100 Subject: [PATCH] Refine save_playlist --- app/playlists.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/app/playlists.py b/app/playlists.py index 06193ba..e923293 100644 --- a/app/playlists.py +++ b/app/playlists.py @@ -718,19 +718,16 @@ class PlaylistTab(QTableWidget): def save_playlist(self, session: Session) -> None: """ - Save playlist to database + All playlist rows have a PlaylistRows id. Check that that id points + to this playlist (in case track has been moved from other) and that + the row number is correct (in case tracks have been reordered). """ - # Iteratate through playlist and check that the row in each - # playlist_row object is correct for row in range(self.rowCount()): plr = session.get(PlaylistRows, self._get_playlistrow_id(row)) - # Set the row number (even if it's already correct) - if plr.row_number != row: - log.debug( - f"Updating PlaylistRow: {plr.row_number=}, {row=}" - ) - plr.row_number = row + # Set the row number and playlist id (even if correct) + plr.row_number = row + plr.playlist_id = self.playlist_id # Any rows in the database with a row_number higher that the # current value of 'row' should not be there. Commit session