Refine save_playlist

This commit is contained in:
Keith Edmunds 2022-08-13 11:06:52 +01:00
parent 5ba70c9c6f
commit f1796451ae

View File

@ -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