WIP: more database updates; all tests run
This commit is contained in:
parent
f9c33120f5
commit
b34e0a014a
37
app/ds.py
37
app/ds.py
@ -434,21 +434,6 @@ def tracks_filtered(filter: Filter) -> list[TrackDTO]:
|
|||||||
return results
|
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
|
# @log_call
|
||||||
def track_update(
|
def track_update(
|
||||||
track_id: int, metadata: dict[str, str | int | float]
|
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
|
# Fixup row number to remove gaps
|
||||||
_playlist_check_playlist(session, playlist_id, fix=True)
|
_playlist_check_playlist(session, playlist_id, fix=True)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
|
||||||
@ -1029,6 +1013,27 @@ def playlistrows_by_playlist(
|
|||||||
return dto_list
|
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
|
# Playdates
|
||||||
# @log_call
|
# @log_call
|
||||||
def playdates_get_last(track_id: int, limit: int = 5) -> str:
|
def playdates_get_last(track_id: int, limit: int = 5) -> str:
|
||||||
|
|||||||
@ -2248,7 +2248,7 @@ class Window(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
intro = round(self.preview_manager.get_playtime() / 100) * 100
|
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.preview_manager.set_intro(intro)
|
||||||
self.current.base_model.refresh_row(row_number)
|
self.current.base_model.refresh_row(row_number)
|
||||||
roles = [
|
roles = [
|
||||||
|
|||||||
@ -1303,14 +1303,21 @@ class PlaylistModel(QAbstractTableModel):
|
|||||||
column = index.column()
|
column = index.column()
|
||||||
plr = self.playlist_rows[row_number]
|
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:
|
if column == Col.TITLE.value:
|
||||||
plr.title = str(value)
|
ds.track_update(track_id, dict(title=str(value)))
|
||||||
elif column == Col.ARTIST.value:
|
elif column == Col.ARTIST.value:
|
||||||
plr.artist = str(value)
|
ds.track_update(track_id, dict(artist=str(value)))
|
||||||
elif column == Col.INTRO.value:
|
elif column == Col.INTRO.value:
|
||||||
plr.intro = int(round(float(value), 1) * 1000)
|
intro = int(round(float(value), 1) * 1000)
|
||||||
elif column == Col.NOTE.value:
|
ds.track_update(track_id, dict(intro=intro))
|
||||||
plr.note = str(value)
|
|
||||||
else:
|
else:
|
||||||
raise ApplicationError(f"setData called with unexpected column ({column=})")
|
raise ApplicationError(f"setData called with unexpected column ({column=})")
|
||||||
|
|
||||||
|
|||||||
@ -70,10 +70,6 @@ class PlaylistRow:
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@artist.setter
|
|
||||||
def artist(self, value: str) -> None:
|
|
||||||
print(f"set artist attribute for {self=}, {value=}")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bitrate(self):
|
def bitrate(self):
|
||||||
if self.dto.track:
|
if self.dto.track:
|
||||||
@ -102,10 +98,6 @@ class PlaylistRow:
|
|||||||
else:
|
else:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@intro.setter
|
|
||||||
def intro(self, value: int) -> None:
|
|
||||||
print(f"set intro attribute for {self=}, {value=}")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def lastplayed(self):
|
def lastplayed(self):
|
||||||
if self.dto.track:
|
if self.dto.track:
|
||||||
@ -141,10 +133,6 @@ class PlaylistRow:
|
|||||||
else:
|
else:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@title.setter
|
|
||||||
def title(self, value: str) -> None:
|
|
||||||
print(f"set title attribute for {self=}, {value=}")
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def track_id(self):
|
def track_id(self):
|
||||||
if self.dto.track:
|
if self.dto.track:
|
||||||
@ -174,22 +162,10 @@ class PlaylistRow:
|
|||||||
def note(self):
|
def note(self):
|
||||||
return self.dto.note
|
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
|
@property
|
||||||
def played(self):
|
def played(self):
|
||||||
return self.dto.played
|
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
|
@property
|
||||||
def playlist_id(self):
|
def playlist_id(self):
|
||||||
return self.dto.playlist_id
|
return self.dto.playlist_id
|
||||||
@ -204,7 +180,8 @@ class PlaylistRow:
|
|||||||
|
|
||||||
@row_number.setter
|
@row_number.setter
|
||||||
def row_number(self, value: int) -> None:
|
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
|
self.dto.row_number = value
|
||||||
|
|
||||||
def check_for_end_of_track(self) -> None:
|
def check_for_end_of_track(self) -> None:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user