WIP: more database updates; all tests run

This commit is contained in:
Keith Edmunds 2025-04-13 19:48:29 +01:00
parent f9c33120f5
commit b34e0a014a
4 changed files with 36 additions and 47 deletions

View File

@ -434,21 +434,6 @@ def tracks_filtered(filter: Filter) -> list[TrackDTO]:
return results
def track_set_intro(track_id: int, intro: int) -> None:
"""
Set track intro time
"""
with db.Session() as session:
session.execute(
update(Tracks)
.where(Tracks.id == track_id)
.values(intro=intro)
)
session.commit()
# @log_call
def track_update(
track_id: int, metadata: dict[str, str | int | float]
@ -918,7 +903,6 @@ def playlist_remove_rows(playlist_id: int, row_numbers: list[int]) -> None:
)
# Fixup row number to remove gaps
_playlist_check_playlist(session, playlist_id, fix=True)
session.commit()
@ -1029,6 +1013,27 @@ def playlistrows_by_playlist(
return dto_list
def playlistrow_update_note(playlistrow_id: int, note: str) -> PlaylistRowDTO:
"""
Update the note on a playlist row
"""
with db.Session() as session:
plr = session.get(PlaylistRows, playlistrow_id)
if not plr:
raise ApplicationError(f"Can't retrieve Playlistrow ({playlistrow_id=})")
plr.note = note
session.commit()
new_plr = playlistrow_by_id(playlistrow_id)
if not new_plr:
raise ApplicationError(f"Can't retrieve new Playlistrow ({playlistrow_id=})")
return new_plr
# Playdates
# @log_call
def playdates_get_last(track_id: int, limit: int = 5) -> str:

View File

@ -2248,7 +2248,7 @@ class Window(QMainWindow):
return
intro = round(self.preview_manager.get_playtime() / 100) * 100
ds.track_set_intro(track_id, intro)
ds.track_update(track_id, dict(intro=intro))
self.preview_manager.set_intro(intro)
self.current.base_model.refresh_row(row_number)
roles = [

View File

@ -1303,14 +1303,21 @@ class PlaylistModel(QAbstractTableModel):
column = index.column()
plr = self.playlist_rows[row_number]
if column == Col.NOTE.value:
ds.playlistrow_update_note(plr.playlistrow_id, str(value))
return True
track_id = plr.track_id
if not track_id:
raise ApplicationError(f"No track_id when editing {plr=}")
if column == Col.TITLE.value:
plr.title = str(value)
ds.track_update(track_id, dict(title=str(value)))
elif column == Col.ARTIST.value:
plr.artist = str(value)
ds.track_update(track_id, dict(artist=str(value)))
elif column == Col.INTRO.value:
plr.intro = int(round(float(value), 1) * 1000)
elif column == Col.NOTE.value:
plr.note = str(value)
intro = int(round(float(value), 1) * 1000)
ds.track_update(track_id, dict(intro=intro))
else:
raise ApplicationError(f"setData called with unexpected column ({column=})")

View File

@ -70,10 +70,6 @@ class PlaylistRow:
else:
return ""
@artist.setter
def artist(self, value: str) -> None:
print(f"set artist attribute for {self=}, {value=}")
@property
def bitrate(self):
if self.dto.track:
@ -102,10 +98,6 @@ class PlaylistRow:
else:
return 0
@intro.setter
def intro(self, value: int) -> None:
print(f"set intro attribute for {self=}, {value=}")
@property
def lastplayed(self):
if self.dto.track:
@ -141,10 +133,6 @@ class PlaylistRow:
else:
return ""
@title.setter
def title(self, value: str) -> None:
print(f"set title attribute for {self=}, {value=}")
@property
def track_id(self):
if self.dto.track:
@ -174,22 +162,10 @@ class PlaylistRow:
def note(self):
return self.dto.note
@note.setter
def note(self, value: str) -> None:
# TODO set up write access to db
print(f"set note attribute for {self=}, {value=}")
# self.dto.note = value
@property
def played(self):
return self.dto.played
@played.setter
def played(self, value: bool = True) -> None:
# TODO set up write access to db
print(f"set played attribute for {self=}")
# self.dto.played = value
@property
def playlist_id(self):
return self.dto.playlist_id
@ -204,7 +180,8 @@ class PlaylistRow:
@row_number.setter
def row_number(self, value: int) -> None:
# TODO do we need to set up write access to db?
# This does not update the database which must take place
# elsewhere
self.dto.row_number = value
def check_for_end_of_track(self) -> None: