Explicitly save playlist id in playlist
This commit is contained in:
parent
52d48406ea
commit
a4bdbfccd0
18
app/model.py
18
app/model.py
@ -286,6 +286,24 @@ class PlaylistTracks(Base):
|
||||
record.row = new_row
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def new_row(session, playlist_id):
|
||||
"Return row number > largest existing row number"
|
||||
|
||||
last_row = session.query(func.max(PlaylistTracks.row)).one()[0]
|
||||
return last_row + 1
|
||||
|
||||
@staticmethod
|
||||
def remove_all_tracks(session, playlist_id):
|
||||
"""
|
||||
Remove all tracks from passed playlist_id
|
||||
"""
|
||||
|
||||
session.query(PlaylistTracks).filter(
|
||||
PlaylistTracks.playlist_id == playlist_id,
|
||||
).delete()
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def remove_track(session, playlist_id, row):
|
||||
DEBUG(
|
||||
|
||||
@ -245,7 +245,7 @@ class Playlist(QTableWidget):
|
||||
|
||||
# We need to add ourself to the session
|
||||
us_in_db = session.query(Playlists).filter(
|
||||
Playlists.id == self.db.id).one()
|
||||
Playlists.id == self.id).one()
|
||||
|
||||
us_in_db.add_track(session, track, row)
|
||||
|
||||
@ -361,9 +361,14 @@ class Playlist(QTableWidget):
|
||||
self._repaint(save_playlist=False)
|
||||
|
||||
def populate(self, session):
|
||||
# add them in row order. We don't mandate that an item will be
|
||||
# add tracks and notes in row order.
|
||||
# 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
|
||||
|
||||
data = []
|
||||
|
||||
for t in self.db.tracks:
|
||||
@ -816,18 +821,20 @@ class Playlist(QTableWidget):
|
||||
|
||||
def _save_playlist(self, session):
|
||||
"""
|
||||
Save playlist to database. We do this by correcting differences
|
||||
between the on-screen (definitive) playlist and that in the
|
||||
database.
|
||||
Save playlist to database.
|
||||
|
||||
We treat the notes rows and the tracks rows differently. Notes must
|
||||
appear only once in only one playlist. Tracks can appear multiple
|
||||
times in one playlist and in multiple playlists.
|
||||
For notes: check the database entry is correct and update it if
|
||||
necessary. Playlists:Note is one:many, so there is only one notes
|
||||
appearance in all playlists.
|
||||
|
||||
For tracks: erase the playlist tracks and recreate. This is much
|
||||
simpler than trying to correct any Playlists:Tracks many:many
|
||||
errors.
|
||||
"""
|
||||
|
||||
# We need to add ourself to the session
|
||||
us_in_db = session.query(Playlists).filter(
|
||||
Playlists.id == self.db.id).one()
|
||||
Playlists.id == self.id).one()
|
||||
|
||||
# Notes first
|
||||
# Create dictionaries indexed by note_id
|
||||
|
||||
Loading…
Reference in New Issue
Block a user