Change PlaylistRows.row_number to plr_rownnum
This commit is contained in:
parent
f3c86484fe
commit
c5c5c28583
@ -203,7 +203,7 @@ class Playlists(Base):
|
|||||||
"PlaylistRows",
|
"PlaylistRows",
|
||||||
back_populates="playlist",
|
back_populates="playlist",
|
||||||
cascade="all, delete-orphan",
|
cascade="all, delete-orphan",
|
||||||
order_by="PlaylistRows.row_no"
|
order_by="PlaylistRows.plr_rownum"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
@ -372,7 +372,7 @@ class PlaylistRows(Base):
|
|||||||
__tablename__ = 'playlist_rows'
|
__tablename__ = 'playlist_rows'
|
||||||
|
|
||||||
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
id: int = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
row_no: int = Column(Integer, nullable=False)
|
plr_rownum: int = Column(Integer, nullable=False)
|
||||||
note: str = Column(String(2048), index=False, default="", nullable=False)
|
note: str = Column(String(2048), index=False, default="", nullable=False)
|
||||||
playlist_id: int = Column(Integer, ForeignKey('playlists.id'),
|
playlist_id: int = Column(Integer, ForeignKey('playlists.id'),
|
||||||
nullable=False)
|
nullable=False)
|
||||||
@ -385,7 +385,7 @@ class PlaylistRows(Base):
|
|||||||
return (
|
return (
|
||||||
f"<PlaylistRow(id={self.id}, playlist_id={self.playlist_id}, "
|
f"<PlaylistRow(id={self.id}, playlist_id={self.playlist_id}, "
|
||||||
f"track_id={self.track_id}, "
|
f"track_id={self.track_id}, "
|
||||||
f"note={self.note}, row_no={self.row_no}>"
|
f"note={self.note}, plr_rownum={self.plr_rownum}>"
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
@ -399,7 +399,7 @@ class PlaylistRows(Base):
|
|||||||
|
|
||||||
self.playlist_id = playlist_id
|
self.playlist_id = playlist_id
|
||||||
self.track_id = track_id
|
self.track_id = track_id
|
||||||
self.row_no = row_number
|
self.plr_rownum = row_number
|
||||||
self.note = note
|
self.note = note
|
||||||
session.add(self)
|
session.add(self)
|
||||||
session.flush()
|
session.flush()
|
||||||
@ -425,7 +425,7 @@ class PlaylistRows(Base):
|
|||||||
).scalars().all()
|
).scalars().all()
|
||||||
|
|
||||||
for plr in src_rows:
|
for plr in src_rows:
|
||||||
PlaylistRows(session, dst_id, plr.track_id, plr.row_no,
|
PlaylistRows(session, dst_id, plr.track_id, plr.plr_rownum,
|
||||||
plr.note)
|
plr.note)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -440,7 +440,7 @@ class PlaylistRows(Base):
|
|||||||
delete(PlaylistRows)
|
delete(PlaylistRows)
|
||||||
.where(
|
.where(
|
||||||
PlaylistRows.playlist_id == playlist_id,
|
PlaylistRows.playlist_id == playlist_id,
|
||||||
PlaylistRows.row_no > maxrow
|
PlaylistRows.plr_rownum > maxrow
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
session.flush()
|
session.flush()
|
||||||
@ -454,11 +454,11 @@ class PlaylistRows(Base):
|
|||||||
plrs = session.execute(
|
plrs = session.execute(
|
||||||
select(PlaylistRows)
|
select(PlaylistRows)
|
||||||
.where(PlaylistRows.playlist_id == playlist_id)
|
.where(PlaylistRows.playlist_id == playlist_id)
|
||||||
.order_by(PlaylistRows.row_no)
|
.order_by(PlaylistRows.plr_rownum)
|
||||||
).scalars().all()
|
).scalars().all()
|
||||||
|
|
||||||
for i, plr in enumerate(plrs):
|
for i, plr in enumerate(plrs):
|
||||||
plr.row_no = i
|
plr.plr_rownum = i
|
||||||
|
|
||||||
# Ensure new row numbers are available to the caller
|
# Ensure new row numbers are available to the caller
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -476,7 +476,7 @@ class PlaylistRows(Base):
|
|||||||
.where(
|
.where(
|
||||||
cls.playlist_id == playlist_id,
|
cls.playlist_id == playlist_id,
|
||||||
cls.id.in_(plr_ids)
|
cls.id.in_(plr_ids)
|
||||||
).order_by(cls.row_no)).scalars().all()
|
).order_by(cls.plr_rownum)).scalars().all()
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
|
|
||||||
@ -486,7 +486,7 @@ class PlaylistRows(Base):
|
|||||||
"""Return the last used row for playlist, or None if no rows"""
|
"""Return the last used row for playlist, or None if no rows"""
|
||||||
|
|
||||||
return session.execute(
|
return session.execute(
|
||||||
select(func.max(PlaylistRows.row_no))
|
select(func.max(PlaylistRows.plr_rownum))
|
||||||
.where(PlaylistRows.playlist_id == playlist_id)
|
.where(PlaylistRows.playlist_id == playlist_id)
|
||||||
).scalar_one()
|
).scalar_one()
|
||||||
|
|
||||||
@ -518,7 +518,7 @@ class PlaylistRows(Base):
|
|||||||
cls.playlist_id == playlist_id,
|
cls.playlist_id == playlist_id,
|
||||||
cls.played.is_(True)
|
cls.played.is_(True)
|
||||||
)
|
)
|
||||||
.order_by(cls.row_no)
|
.order_by(cls.plr_rownum)
|
||||||
).scalars().all()
|
).scalars().all()
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
@ -538,12 +538,12 @@ class PlaylistRows(Base):
|
|||||||
cls.track_id.is_not(None)
|
cls.track_id.is_not(None)
|
||||||
)
|
)
|
||||||
if from_row is not None:
|
if from_row is not None:
|
||||||
query = query.where(cls.row_no >= from_row)
|
query = query.where(cls.plr_rownum >= from_row)
|
||||||
if to_row is not None:
|
if to_row is not None:
|
||||||
query = query.where(cls.row_no <= to_row)
|
query = query.where(cls.plr_rownum <= to_row)
|
||||||
|
|
||||||
plrs = (
|
plrs = (
|
||||||
session.execute((query).order_by(cls.row_no)).scalars().all()
|
session.execute((query).order_by(cls.plr_rownum)).scalars().all()
|
||||||
)
|
)
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
@ -563,7 +563,7 @@ class PlaylistRows(Base):
|
|||||||
cls.track_id.is_not(None),
|
cls.track_id.is_not(None),
|
||||||
cls.played.is_(False)
|
cls.played.is_(False)
|
||||||
)
|
)
|
||||||
.order_by(cls.row_no)
|
.order_by(cls.plr_rownum)
|
||||||
).scalars().all()
|
).scalars().all()
|
||||||
|
|
||||||
return plrs
|
return plrs
|
||||||
@ -580,9 +580,9 @@ class PlaylistRows(Base):
|
|||||||
update(PlaylistRows)
|
update(PlaylistRows)
|
||||||
.where(
|
.where(
|
||||||
(PlaylistRows.playlist_id == playlist_id),
|
(PlaylistRows.playlist_id == playlist_id),
|
||||||
(PlaylistRows.row_no >= starting_row)
|
(PlaylistRows.plr_rownum >= starting_row)
|
||||||
)
|
)
|
||||||
.values(row_no=PlaylistRows.row_no + move_by)
|
.values(plr_rownum=PlaylistRows.plr_rownum + move_by)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -997,8 +997,8 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
self.next_track.plr_id]
|
self.next_track.plr_id]
|
||||||
]
|
]
|
||||||
|
|
||||||
rows_to_delete = [plr.row_no for plr in plrs_to_move
|
rows_to_delete = [plr.plr_rownum for plr in plrs_to_move
|
||||||
if plr.row_no is not None]
|
if plr.plr_rownum is not None]
|
||||||
if not rows_to_delete:
|
if not rows_to_delete:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1028,7 +1028,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
next_row = 0
|
next_row = 0
|
||||||
|
|
||||||
for plr in plrs_to_move:
|
for plr in plrs_to_move:
|
||||||
plr.row_no = next_row
|
plr.plr_rownum = next_row
|
||||||
next_row += 1
|
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
|
||||||
@ -1150,7 +1150,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
|||||||
if not src_playlist_id:
|
if not src_playlist_id:
|
||||||
src_playlist_id = plr.playlist_id
|
src_playlist_id = plr.playlist_id
|
||||||
plr.playlist_id = dst_playlist_id
|
plr.playlist_id = dst_playlist_id
|
||||||
plr.row_no = row
|
plr.plr_rownum = row
|
||||||
row += 1
|
row += 1
|
||||||
|
|
||||||
if not src_playlist_id:
|
if not src_playlist_id:
|
||||||
|
|||||||
@ -531,7 +531,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
Insert passed playlist row (plr) into playlist tab.
|
Insert passed playlist row (plr) into playlist tab.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
row_number = plr.row_no
|
row_number = plr.plr_rownum
|
||||||
bold = True
|
bold = True
|
||||||
self.insertRow(row_number)
|
self.insertRow(row_number)
|
||||||
_ = self._set_row_plr_id(row_number, plr.id)
|
_ = self._set_row_plr_id(row_number, plr.id)
|
||||||
@ -695,7 +695,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
for plr in playlist.rows:
|
for plr in playlist.rows:
|
||||||
self.insert_row(session, plr, update_track_times=False,
|
self.insert_row(session, plr, update_track_times=False,
|
||||||
played=plr.row_no in played_rows)
|
played=plr.plr_rownum in played_rows)
|
||||||
|
|
||||||
# Scroll to top
|
# Scroll to top
|
||||||
if scroll_to_top:
|
if scroll_to_top:
|
||||||
@ -756,7 +756,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
plr = self._get_row_plr(session, row_number)
|
plr = self._get_row_plr(session, row_number)
|
||||||
if not plr:
|
if not plr:
|
||||||
continue
|
continue
|
||||||
plr.row_no = row_number
|
plr.plr_rownum = row_number
|
||||||
plr.playlist_id = self.playlist_id
|
plr.playlist_id = self.playlist_id
|
||||||
|
|
||||||
# Any rows in the database for this playlist that has a row
|
# Any rows in the database for this playlist that has a row
|
||||||
@ -1086,7 +1086,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
f"Really delete {row_count} row{plural}?"):
|
f"Really delete {row_count} row{plural}?"):
|
||||||
return
|
return
|
||||||
|
|
||||||
rows_to_delete = [plr.row_no for plr in plrs]
|
rows_to_delete = [plr.plr_rownum for plr in plrs]
|
||||||
|
|
||||||
# Delete rows from database. Would be more efficient to
|
# Delete rows from database. Would be more efficient to
|
||||||
# query then have a single delete.
|
# query then have a single delete.
|
||||||
@ -1133,11 +1133,11 @@ class PlaylistTab(QTableWidget):
|
|||||||
starting_row = 0
|
starting_row = 0
|
||||||
|
|
||||||
track_rows = [
|
track_rows = [
|
||||||
p.row_no for p in PlaylistRows.get_rows_with_tracks(
|
p.plr_rownum for p in PlaylistRows.get_rows_with_tracks(
|
||||||
session, self.playlist_id)
|
session, self.playlist_id)
|
||||||
]
|
]
|
||||||
played_rows = [
|
played_rows = [
|
||||||
p.row_no for p in PlaylistRows.get_played_rows(
|
p.plr_rownum for p in PlaylistRows.get_played_rows(
|
||||||
session, self.playlist_id)
|
session, self.playlist_id)
|
||||||
]
|
]
|
||||||
for row_number in range(starting_row, self.rowCount()):
|
for row_number in range(starting_row, self.rowCount()):
|
||||||
@ -1194,8 +1194,8 @@ class PlaylistTab(QTableWidget):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return [
|
return [
|
||||||
p.row_no for p in PlaylistRows.get_played_rows(
|
p.plr_rownum for p in PlaylistRows.get_played_rows(
|
||||||
session, self.playlist_id) if p.row_no is not None
|
session, self.playlist_id) if p.plr_rownum is not None
|
||||||
]
|
]
|
||||||
|
|
||||||
def _get_row_artist(self, row_number: int) -> str:
|
def _get_row_artist(self, row_number: int) -> str:
|
||||||
@ -1407,16 +1407,16 @@ class PlaylistTab(QTableWidget):
|
|||||||
new_row_number: int) -> None:
|
new_row_number: int) -> None:
|
||||||
"""Move playlist row to new_row_number using parent copy/paste"""
|
"""Move playlist row to new_row_number using parent copy/paste"""
|
||||||
|
|
||||||
if plr.row_no is None:
|
if plr.plr_rownum is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Remove source row
|
# Remove source row
|
||||||
self.removeRow(plr.row_no)
|
self.removeRow(plr.plr_rownum)
|
||||||
# Fixup plr row number
|
# Fixup plr row number
|
||||||
if plr.row_no < new_row_number:
|
if plr.plr_rownum < new_row_number:
|
||||||
plr.row_no = new_row_number - 1
|
plr.plr_rownum = new_row_number - 1
|
||||||
else:
|
else:
|
||||||
plr.row_no = new_row_number
|
plr.plr_rownum = new_row_number
|
||||||
self.insert_row(session, plr)
|
self.insert_row(session, plr)
|
||||||
self.save_playlist(session)
|
self.save_playlist(session)
|
||||||
self.hide_or_show_played_tracks()
|
self.hide_or_show_played_tracks()
|
||||||
@ -1728,7 +1728,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
|
|
||||||
# Unmark next track
|
# Unmark next track
|
||||||
if old_plr and old_plr.playlist_id == self.playlist_id:
|
if old_plr and old_plr.playlist_id == self.playlist_id:
|
||||||
self._set_row_colour_default(old_plr.row_no)
|
self._set_row_colour_default(old_plr.plr_rownum)
|
||||||
|
|
||||||
# Mark next track
|
# Mark next track
|
||||||
if new_plrid:
|
if new_plrid:
|
||||||
@ -1737,7 +1737,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
log.error(f"_reset_next({new_plrid=}): plr not found")
|
log.error(f"_reset_next({new_plrid=}): plr not found")
|
||||||
return
|
return
|
||||||
if new_plr.playlist_id == self.playlist_id:
|
if new_plr.playlist_id == self.playlist_id:
|
||||||
self._set_row_colour_next(new_plr.row_no)
|
self._set_row_colour_next(new_plr.plr_rownum)
|
||||||
|
|
||||||
# Update start/stop times
|
# Update start/stop times
|
||||||
self._update_start_end_times(session)
|
self._update_start_end_times(session)
|
||||||
@ -2082,7 +2082,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
plr_tracks = PlaylistRows.get_rows_with_tracks(
|
plr_tracks = PlaylistRows.get_rows_with_tracks(
|
||||||
session, self.playlist_id, from_plr.row_no, to_plr.row_no)
|
session, self.playlist_id, from_plr.plr_rownum, to_plr.plr_rownum)
|
||||||
|
|
||||||
total_time = 0
|
total_time = 0
|
||||||
total_time = sum([a.track.duration for a in plr_tracks
|
total_time = sum([a.track.duration for a in plr_tracks
|
||||||
@ -2134,7 +2134,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
total_time = self._track_time_between_rows(
|
total_time = self._track_time_between_rows(
|
||||||
session, from_plr, to_plr)
|
session, from_plr, to_plr)
|
||||||
time_str = self._get_section_timing_string(total_time)
|
time_str = self._get_section_timing_string(total_time)
|
||||||
self._set_row_header_text(session, from_plr.row_no,
|
self._set_row_header_text(session, from_plr.plr_rownum,
|
||||||
from_plr.note + time_str)
|
from_plr.note + time_str)
|
||||||
|
|
||||||
# Update section end
|
# Update section end
|
||||||
@ -2144,12 +2144,12 @@ class PlaylistTab(QTableWidget):
|
|||||||
section_header_cleanup_re, '', from_plr.note,
|
section_header_cleanup_re, '', from_plr.note,
|
||||||
).strip() + "]"
|
).strip() + "]"
|
||||||
)
|
)
|
||||||
self._set_row_header_text(session, to_plr.row_no,
|
self._set_row_header_text(session, to_plr.plr_rownum,
|
||||||
new_text)
|
new_text)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# This ending row may have a time left from before a
|
# This ending row may have a time left from before a
|
||||||
# starting row above was deleted, so replace content
|
# starting row above was deleted, so replace content
|
||||||
self._set_row_header_text(session, plr.row_no,
|
self._set_row_header_text(session, plr.plr_rownum,
|
||||||
plr.note)
|
plr.note)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
@ -2163,7 +2163,7 @@ class PlaylistTab(QTableWidget):
|
|||||||
from_plr, to_plr)
|
from_plr, to_plr)
|
||||||
time_str = self._get_section_timing_string(total_time,
|
time_str = self._get_section_timing_string(total_time,
|
||||||
no_end=True)
|
no_end=True)
|
||||||
self._set_row_header_text(session, from_plr.row_no,
|
self._set_row_header_text(session, from_plr.plr_rownum,
|
||||||
from_plr.note + time_str)
|
from_plr.note + time_str)
|
||||||
|
|
||||||
def _update_start_end_times(self, session: scoped_session) -> None:
|
def _update_start_end_times(self, session: scoped_session) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user