WIP V3: delete rows works
This commit is contained in:
parent
9467ae4ee5
commit
71f3e4cda8
@ -431,23 +431,6 @@ class PlaylistRows(Base):
|
|||||||
track_id=plr.track_id,
|
track_id=plr.track_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def delete_higher_rows(
|
|
||||||
session: scoped_session, playlist_id: int, maxrow: int
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Delete rows in given playlist that have a higher row number
|
|
||||||
than 'maxrow'
|
|
||||||
"""
|
|
||||||
|
|
||||||
session.execute(
|
|
||||||
delete(PlaylistRows).where(
|
|
||||||
PlaylistRows.playlist_id == playlist_id,
|
|
||||||
PlaylistRows.plr_rownum > maxrow,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
session.flush()
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def deep_row(
|
def deep_row(
|
||||||
cls, session: scoped_session, playlist_id: int, row_number: int
|
cls, session: scoped_session, playlist_id: int, row_number: int
|
||||||
@ -488,6 +471,36 @@ class PlaylistRows(Base):
|
|||||||
|
|
||||||
return session.scalars(stmt).unique().all()
|
return session.scalars(stmt).unique().all()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_higher_rows(
|
||||||
|
session: scoped_session, playlist_id: int, maxrow: int
|
||||||
|
) -> None:
|
||||||
|
"""
|
||||||
|
Delete rows in given playlist that have a higher row number
|
||||||
|
than 'maxrow'
|
||||||
|
"""
|
||||||
|
|
||||||
|
session.execute(
|
||||||
|
delete(PlaylistRows).where(
|
||||||
|
PlaylistRows.playlist_id == playlist_id,
|
||||||
|
PlaylistRows.plr_rownum > maxrow,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
session.flush()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete_rows(session: scoped_session, playlist_id: int, row_numbers: List[int]) -> None:
|
||||||
|
"""
|
||||||
|
Delete passed rows in given playlist.
|
||||||
|
"""
|
||||||
|
|
||||||
|
session.execute(
|
||||||
|
delete(PlaylistRows).where(
|
||||||
|
PlaylistRows.playlist_id == playlist_id,
|
||||||
|
PlaylistRows.plr_rownum.in_(row_numbers)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def fixup_rownumbers(session: scoped_session, playlist_id: int) -> None:
|
def fixup_rownumbers(session: scoped_session, playlist_id: int) -> None:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -347,8 +347,11 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
Delete passed rows from model
|
Delete passed rows from model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# TODO
|
with Session() as session:
|
||||||
print(f"Delete rows {row_numbers=}")
|
PlaylistRows.delete_rows(session, self.playlist_id, row_numbers)
|
||||||
|
PlaylistRows.fixup_rownumbers(session, self.playlist_id)
|
||||||
|
self.refresh_data(session)
|
||||||
|
self.update_track_times()
|
||||||
|
|
||||||
def display_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
def display_role(self, row: int, column: int, prd: PlaylistRowData) -> QVariant:
|
||||||
"""
|
"""
|
||||||
|
|||||||
@ -1085,9 +1085,7 @@ class PlaylistTab(QTableView):
|
|||||||
|
|
||||||
# Delete row
|
# Delete row
|
||||||
if not current_row and not next_row:
|
if not current_row and not next_row:
|
||||||
self._add_context_menu(
|
self._add_context_menu("Delete row", lambda: self._delete_rows())
|
||||||
"Delete row", lambda: model.delete_rows(self._get_selected_rows())
|
|
||||||
)
|
|
||||||
|
|
||||||
# Remove track from row
|
# Remove track from row
|
||||||
if track_row and not current_row and not next_row:
|
if track_row and not current_row and not next_row:
|
||||||
@ -1211,77 +1209,22 @@ class PlaylistTab(QTableView):
|
|||||||
Delete mutliple rows
|
Delete mutliple rows
|
||||||
|
|
||||||
Actions required:
|
Actions required:
|
||||||
- Remove the rows from the display
|
- Confirm deletion should go ahead
|
||||||
- Save the playlist
|
- Pass to model to do the deed
|
||||||
- Update track start/end times
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
rows_to_delete: List[int] = []
|
rows_to_delete = self._get_selected_rows()
|
||||||
with Session() as session:
|
row_count = len(rows_to_delete)
|
||||||
plrs = self.get_selected_playlistrows(session)
|
if row_count < 1:
|
||||||
row_count = len(plrs)
|
return
|
||||||
if not row_count:
|
|
||||||
return
|
|
||||||
|
|
||||||
# Get confirmation
|
# Get confirmation
|
||||||
plural = "s" if row_count > 1 else ""
|
plural = "s" if row_count > 1 else ""
|
||||||
if not ask_yes_no("Delete rows", f"Really delete {row_count} row{plural}?"):
|
if not ask_yes_no("Delete rows", f"Really delete {row_count} row{plural}?"):
|
||||||
return
|
return
|
||||||
|
|
||||||
rows_to_delete = [plr.plr_rownum for plr in plrs]
|
model = cast(PlaylistModel, self.model())
|
||||||
|
model.delete_rows(self._get_selected_rows())
|
||||||
# Delete rows from database. Would be more efficient to
|
|
||||||
# query then have a single delete.
|
|
||||||
for plr in plrs:
|
|
||||||
session.delete(plr)
|
|
||||||
|
|
||||||
# Remove from display
|
|
||||||
self.remove_rows(rows_to_delete)
|
|
||||||
|
|
||||||
# Need to save the playlist to ensure the PlaylistRows have
|
|
||||||
# the correct row_number
|
|
||||||
self.save_playlist(session)
|
|
||||||
|
|
||||||
# Reset drag mode
|
|
||||||
# self.setDragEnabled(False)
|
|
||||||
|
|
||||||
self._update_start_end_times(session)
|
|
||||||
|
|
||||||
# def _find_next_track_row(
|
|
||||||
# self, session: scoped_session, starting_row: Optional[int] = None
|
|
||||||
# ) -> Optional[int]:
|
|
||||||
# """
|
|
||||||
# Find next track to play. If a starting row is given, start there;
|
|
||||||
# otherwise, start from top. Skip rows already played.
|
|
||||||
|
|
||||||
# If not found, return None.
|
|
||||||
|
|
||||||
# If found, return row number.
|
|
||||||
# """
|
|
||||||
|
|
||||||
# if starting_row is None:
|
|
||||||
# starting_row = 0
|
|
||||||
|
|
||||||
# track_rows = [
|
|
||||||
# p.plr_rownum
|
|
||||||
# for p in PlaylistRows.get_rows_with_tracks(session, self.playlist_id)
|
|
||||||
# ]
|
|
||||||
# played_rows = [
|
|
||||||
# p.plr_rownum
|
|
||||||
# for p in PlaylistRows.get_played_rows(session, self.playlist_id)
|
|
||||||
# ]
|
|
||||||
# for row_number in range(starting_row, self.rowCount()):
|
|
||||||
# if row_number not in track_rows or row_number in played_rows:
|
|
||||||
# continue
|
|
||||||
# plr = selWIP V3: play track workingf._get_row_plr(session, row_number)
|
|
||||||
# if not plr:
|
|
||||||
# continue
|
|
||||||
# if file_is_unreadable(plr.track.path):
|
|
||||||
# continue
|
|
||||||
# else:
|
|
||||||
# return row_number
|
|
||||||
|
|
||||||
# return None
|
|
||||||
|
|
||||||
def _get_current_track_row_number(self) -> Optional[int]:
|
def _get_current_track_row_number(self) -> Optional[int]:
|
||||||
"""Return current track row or None"""
|
"""Return current track row or None"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user