From 7a6c8a0f95bde34a53cae7684158a3538eb4e3c3 Mon Sep 17 00:00:00 2001 From: Keith Edmunds Date: Fri, 19 Jul 2024 12:46:10 +0100 Subject: [PATCH] Mark playlist last used on creation Fixes #249 --- app/models.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/models.py b/app/models.py index a348e0c..275ca74 100644 --- a/app/models.py +++ b/app/models.py @@ -65,7 +65,8 @@ class NoteColours(dbtables.NoteColoursTable): Return all records """ - return session.scalars(select(cls)).all() + result = session.scalars(select(cls)).all() + return result @staticmethod def get_colour(session: Session, text: str) -> Optional[str]: @@ -167,6 +168,7 @@ class Playdates(dbtables.PlaydatesTable): class Playlists(dbtables.PlaylistsTable): def __init__(self, session: Session, name: str): self.name = name + self.last_used = dt.datetime.now() session.add(self) session.commit() @@ -192,10 +194,14 @@ class Playlists(dbtables.PlaylistsTable): ) -> Optional["Playlists"]: """Create a new playlist from template""" + # Sanity check + if not template.id: + return None + playlist = cls(session, playlist_name) # Sanity / mypy checks - if not playlist or not playlist.id or not template.id: + if not playlist or not playlist.id: return None PlaylistRows.copy_playlist(session, template.id, playlist.id)