parent
74028fadf7
commit
046b689882
@ -140,9 +140,8 @@ class PlaylistTrack:
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return (
|
return (
|
||||||
f"<PlaylistTrack(id={self.id}, title={self.title}, "
|
f"<PlaylistTrack(title={self.title}, artist={self.artist}, "
|
||||||
f"artist={self.artist}, row_number={self.row_number} ",
|
f"row_number={self.row_number} playlist_id={self.playlist_id}>"
|
||||||
f"playlist_id={self.playlist_id}>"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def set_plr(self, session: Session, plr: PlaylistRows,
|
def set_plr(self, session: Session, plr: PlaylistRows,
|
||||||
@ -840,23 +839,29 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
Move passed playlist rows to another playlist
|
Move passed playlist rows to another playlist
|
||||||
|
|
||||||
Actions required:
|
Actions required:
|
||||||
|
- exclude current/next tracks from being moved
|
||||||
- identify destination playlist
|
- identify destination playlist
|
||||||
- update playlist for the rows in the database
|
- update playlist for the rows in the database
|
||||||
- remove them from the display
|
- remove them from the display
|
||||||
- update destination playlist display if loaded
|
- update destination playlist display if loaded
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if not playlistrows:
|
# Remove current/next rows from list
|
||||||
log.debug(f"musicmuster.move_playlist_rows({playlistrows=}")
|
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
|
# Identify destination playlist
|
||||||
visible_tab = self.visible_playlist_tab()
|
|
||||||
source_playlist = visible_tab.playlist_id
|
|
||||||
|
|
||||||
# Get destination playlist id
|
|
||||||
playlists = []
|
playlists = []
|
||||||
|
visible_tab = self.visible_playlist_tab()
|
||||||
|
source_playlist_id = visible_tab.playlist_id
|
||||||
|
|
||||||
for playlist in Playlists.get_all(session):
|
for playlist in Playlists.get_all(session):
|
||||||
if playlist.id == source_playlist:
|
if playlist.id == source_playlist_id:
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
playlists.append(playlist)
|
playlists.append(playlist)
|
||||||
@ -867,10 +872,6 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
return
|
return
|
||||||
destination_playlist_id = dlg.playlist.id
|
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
|
# Update destination playlist in the database
|
||||||
last_row = PlaylistRows.get_last_used_row(session,
|
last_row = PlaylistRows.get_last_used_row(session,
|
||||||
destination_playlist_id)
|
destination_playlist_id)
|
||||||
@ -879,11 +880,17 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
else:
|
else:
|
||||||
next_row = 0
|
next_row = 0
|
||||||
|
|
||||||
for plr in playlistrows:
|
for plr in plrs_to_move:
|
||||||
plr.row_number = next_row
|
plr.row_number = next_row
|
||||||
|
next_row += 1
|
||||||
plr.playlist_id = destination_playlist_id
|
plr.playlist_id = destination_playlist_id
|
||||||
# Reset played as it's not been played on this playlist
|
# Reset played as it's not been played on this playlist
|
||||||
plr.played = False
|
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
|
# Update destination playlist_tab if visible (if not visible, it
|
||||||
# will be re-populated when it is opened)
|
# 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
|
playlist_id = self.visible_playlist_tab().playlist_id
|
||||||
with Session() as session:
|
with Session() as session:
|
||||||
unplayed_playlist_rows = PlaylistRows.get_unplayed_rows(
|
unplayed_plrs = PlaylistRows.get_unplayed_rows(
|
||||||
session, playlist_id)
|
session, playlist_id)
|
||||||
if helpers.ask_yes_no("Move tracks",
|
if helpers.ask_yes_no("Move tracks",
|
||||||
f"Move {len(unplayed_playlist_rows)} tracks:"
|
f"Move {len(unplayed_playlist_rows)} tracks:"
|
||||||
" Are you sure?"
|
" Are you sure?"
|
||||||
):
|
):
|
||||||
self.move_playlist_rows(session, unplayed_playlist_rows)
|
self.move_playlist_rows(session, unplayed_plrs)
|
||||||
|
|
||||||
def new_from_template(self) -> None:
|
def new_from_template(self) -> None:
|
||||||
"""Create new playlist from template"""
|
"""Create new playlist from template"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user