Fix deleting rows from playlist
This commit is contained in:
parent
46f2b662f3
commit
f2a27366d3
@ -453,24 +453,22 @@ class PlaylistRows(Base):
|
||||
plr.note)
|
||||
|
||||
@staticmethod
|
||||
def delete_higher_rows(session: Session, playlist_id: int, maxrow: int) \
|
||||
-> None:
|
||||
def delete_plrids_not_in_list(session: Session, playlist_id: int,
|
||||
plrids: List["PlaylistRows"]) -> None:
|
||||
"""
|
||||
Delete rows in given playlist that have a higher row number
|
||||
than 'maxrow'
|
||||
"""
|
||||
|
||||
# Log the rows to be deleted
|
||||
rows_to_go = session.execute(
|
||||
select(PlaylistRows)
|
||||
.where(PlaylistRows.playlist_id == playlist_id,
|
||||
PlaylistRows.row_number > maxrow)
|
||||
).scalars().all()
|
||||
if not rows_to_go:
|
||||
return
|
||||
|
||||
for row in rows_to_go:
|
||||
session.delete(row)
|
||||
session.execute(
|
||||
delete(PlaylistRows)
|
||||
.where(
|
||||
PlaylistRows.playlist_id == playlist_id,
|
||||
PlaylistRows.id.not_in(plrids)
|
||||
)
|
||||
)
|
||||
# Delete won't take effect until commit()
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def delete_rows(session: Session, ids: List[int]) -> None:
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
from log import log
|
||||
import argparse
|
||||
import stackprinter
|
||||
import stackprinter # type: ignore
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
|
||||
@ -327,8 +327,8 @@ class PlaylistTab(QTableWidget):
|
||||
act_setnext.triggered.connect(
|
||||
lambda: self._set_next(session, row_number))
|
||||
|
||||
# Open in Audacity
|
||||
if not current:
|
||||
# Open in Audacity
|
||||
act_audacity = self.menu.addAction(
|
||||
"Open in Audacity")
|
||||
act_audacity.triggered.connect(
|
||||
@ -778,7 +778,7 @@ class PlaylistTab(QTableWidget):
|
||||
self.current_track_start_time = None
|
||||
|
||||
def populate_display(self, session: Session, playlist_id: int,
|
||||
scroll_to_top: bool = True) -> None:
|
||||
scroll_to_top: bool = True) -> None:
|
||||
"""
|
||||
Populate display from the associated playlist ID
|
||||
"""
|
||||
@ -854,13 +854,13 @@ class PlaylistTab(QTableWidget):
|
||||
row_plr[row].row_number = row
|
||||
row_plr[row].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
|
||||
# first to ensure any changes made above are committed.
|
||||
session.commit()
|
||||
PlaylistRows.delete_higher_rows(session, self.playlist_id,
|
||||
self.rowCount() - 1)
|
||||
# Any rows in the database for this playlist that have a plr id
|
||||
# that's not in the displayed playlist need to be deleted.
|
||||
|
||||
# Ensure changes flushed
|
||||
session.commit()
|
||||
PlaylistRows.delete_plrids_not_in_list(session, self.playlist_id,
|
||||
display_plr_ids.values())
|
||||
|
||||
def scroll_current_to_top(self) -> None:
|
||||
"""Scroll currently-playing row to top"""
|
||||
@ -1325,7 +1325,7 @@ class PlaylistTab(QTableWidget):
|
||||
self.remove_selected_rows()
|
||||
|
||||
with Session() as session:
|
||||
self.save_playlist(session)
|
||||
QTimer.singleShot(0, lambda: self.save_playlist(session))
|
||||
|
||||
def _drop_on(self, event):
|
||||
"""
|
||||
|
||||
Loading…
Reference in New Issue
Block a user