diff --git a/app/models.py b/app/models.py index 1cd8900..8516da3 100644 --- a/app/models.py +++ b/app/models.py @@ -161,6 +161,19 @@ class Playdates(dbtables.PlaydatesTable): # last_played value return Config.EPOCH # pragma: no cover + @staticmethod + def last_played_tracks(session: Session, limit=5) -> Sequence["Playdates"]: + """ + Return a list of the last limit tracks played, sorted + earliest to latest. + """ + + return session.scalars( + Playdates.select() + .order_by(Playdates.lastplayed.desc()) + .limit(limit) + ).all() + @staticmethod def played_after(session: Session, since: dt.datetime) -> Sequence["Playdates"]: """Return a list of Playdates objects since passed time""" diff --git a/app/musicmuster.py b/app/musicmuster.py index 0c838e4..19ad76c 100755 --- a/app/musicmuster.py +++ b/app/musicmuster.py @@ -1178,6 +1178,15 @@ class Window(QMainWindow, Ui_MainWindow): # Update headers log.debug("update headers") self.update_headers() + with db.Session() as session: + last_played = Playdates.last_played_tracks(session) + tracklist = [] + for lp in last_played: + track = session.get(Tracks, lp.track_id) + tracklist.append(f"{track.title} ({track.artist})") + tt = "
".join(reversed(tracklist)) + + self.hdrPreviousTrack.setToolTip(tt) def preview(self) -> None: """