diff --git a/app/musicmuster.py b/app/musicmuster.py index 315aef8..6901304 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -140,9 +140,8 @@ class PlaylistTrack: def __repr__(self) -> str: return ( - f"" + f"" ) def set_plr(self, session: Session, plr: PlaylistRows, @@ -840,23 +839,29 @@ class Window(QMainWindow, Ui_MainWindow): Move passed playlist rows to another playlist Actions required: + - exclude current/next tracks from being moved - identify destination playlist - update playlist for the rows in the database - remove them from the display - update destination playlist display if loaded """ - if not playlistrows: - log.debug(f"musicmuster.move_playlist_rows({playlistrows=}") + # Remove current/next rows from list + plrs_to_move = [plr for plr in playlistrows if + plr.id not in + [self.current_track.plr_id, + self.next_track.plr_id] + ] + + rows_to_delete = [plr.row_number for plr in plrs_to_move] # Identify destination playlist - visible_tab = self.visible_playlist_tab() - source_playlist = visible_tab.playlist_id - - # Get destination playlist id playlists = [] + visible_tab = self.visible_playlist_tab() + source_playlist_id = visible_tab.playlist_id + for playlist in Playlists.get_all(session): - if playlist.id == source_playlist: + if playlist.id == source_playlist_id: continue else: playlists.append(playlist) @@ -867,10 +872,6 @@ class Window(QMainWindow, Ui_MainWindow): return destination_playlist_id = dlg.playlist.id - # Remove moved rows from display and save - visible_tab.remove_rows([plr.row_number for plr in playlistrows]) - visible_tab.save_playlist(session) - # Update destination playlist in the database last_row = PlaylistRows.get_last_used_row(session, destination_playlist_id) @@ -879,11 +880,17 @@ class Window(QMainWindow, Ui_MainWindow): else: next_row = 0 - for plr in playlistrows: + for plr in plrs_to_move: plr.row_number = next_row + next_row += 1 plr.playlist_id = destination_playlist_id # Reset played as it's not been played on this playlist plr.played = False + session.commit() + + # Remove moved rows from display and save visible playlist + visible_tab.remove_rows(rows_to_delete) + visible_tab.save_playlist(session) # Update destination playlist_tab if visible (if not visible, it # will be re-populated when it is opened) @@ -919,13 +926,13 @@ class Window(QMainWindow, Ui_MainWindow): playlist_id = self.visible_playlist_tab().playlist_id with Session() as session: - unplayed_playlist_rows = PlaylistRows.get_unplayed_rows( + unplayed_plrs = PlaylistRows.get_unplayed_rows( session, playlist_id) if helpers.ask_yes_no("Move tracks", f"Move {len(unplayed_playlist_rows)} tracks:" " Are you sure?" ): - self.move_playlist_rows(session, unplayed_playlist_rows) + self.move_playlist_rows(session, unplayed_plrs) def new_from_template(self) -> None: """Create new playlist from template"""