Remove link to database object from playlist. Fixes #16
This commit is contained in:
parent
e498457395
commit
c5f5155332
@ -285,8 +285,7 @@ class Window(QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
|
||||
playlist_table = Playlist(self)
|
||||
playlist_table.db = playlist_db
|
||||
playlist_table.populate(session)
|
||||
playlist_table.populate(session, playlist_db)
|
||||
idx = self.tabPlaylist.addTab(playlist_table, playlist_db.name)
|
||||
self.tabPlaylist.setCurrentIndex(idx)
|
||||
|
||||
|
||||
@ -244,10 +244,10 @@ class Playlist(QTableWidget):
|
||||
DEBUG(f"playlists.add_track(track={track}), row={row}")
|
||||
|
||||
# We need to add ourself to the session
|
||||
us_in_db = session.query(Playlists).filter(
|
||||
playlist_db = session.query(Playlists).filter(
|
||||
Playlists.id == self.id).one()
|
||||
|
||||
us_in_db.add_track(session, track, row)
|
||||
playlist_db.add_track(session, track, row)
|
||||
|
||||
self.insertRow(row)
|
||||
|
||||
@ -360,21 +360,24 @@ class Playlist(QTableWidget):
|
||||
self.current_track_start_time = None
|
||||
self._repaint()
|
||||
|
||||
def populate(self, session):
|
||||
# add tracks and notes in row order.
|
||||
def populate(self, session, playlist_db):
|
||||
"""
|
||||
Populate ourself from the passed playlist_db object
|
||||
"""
|
||||
|
||||
# We don't mandate that an item will be
|
||||
# on its specified row, only that it will be above
|
||||
# larger-numbered row items, and below lower-numbered ones.
|
||||
|
||||
# First, save our id for the future
|
||||
self.id = self.db.id
|
||||
self.name = self.db.name
|
||||
self.id = playlist_db.id
|
||||
self.name = playlist_db.name
|
||||
|
||||
data = []
|
||||
|
||||
for t in self.db.tracks:
|
||||
for t in playlist_db.tracks:
|
||||
data.append(([t.row], t.tracks))
|
||||
for n in self.db.notes:
|
||||
for n in playlist_db.notes:
|
||||
data.append(([n.row], n))
|
||||
|
||||
# Clear playlist
|
||||
@ -388,7 +391,6 @@ class Playlist(QTableWidget):
|
||||
scroll_to = self.item(0, self.COL_INDEX)
|
||||
self.scrollToItem(scroll_to, QAbstractItemView.PositionAtTop)
|
||||
|
||||
self._save_playlist(session)
|
||||
self._repaint()
|
||||
|
||||
def repaint(self):
|
||||
@ -834,7 +836,7 @@ class Playlist(QTableWidget):
|
||||
"""
|
||||
|
||||
# We need to add ourself to the session
|
||||
us_in_db = session.query(Playlists).filter(
|
||||
playlist_db = session.query(Playlists).filter(
|
||||
Playlists.id == self.id).one()
|
||||
|
||||
# Notes first
|
||||
@ -852,7 +854,7 @@ class Playlist(QTableWidget):
|
||||
playlist_notes[note_id] = row
|
||||
|
||||
# Database
|
||||
for note in us_in_db.notes:
|
||||
for note in playlist_db.notes:
|
||||
database_notes[note.id] = note.row
|
||||
|
||||
# Notes to add to database
|
||||
@ -861,14 +863,14 @@ class Playlist(QTableWidget):
|
||||
for note_id in set(playlist_notes.keys()) - set(database_notes.keys()):
|
||||
ERROR(
|
||||
f"_save_playlist(): Note.id={note_id} "
|
||||
f"missing from playlist {us_in_db} in database"
|
||||
f"missing from playlist {playlist_db} in database"
|
||||
)
|
||||
|
||||
# Notes to remove from database
|
||||
for note_id in set(database_notes.keys()) - set(playlist_notes.keys()):
|
||||
DEBUG(
|
||||
f"_save_playlist(): Delete note note_id={note_id} "
|
||||
f"from playlist {us_in_db} in database"
|
||||
f"from playlist {playlist_db} in database"
|
||||
)
|
||||
Notes.delete_note(session, note_id)
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user