More DEBUG message improvements
This commit is contained in:
parent
69ba659d73
commit
f550c8944f
36
app/model.py
36
app/model.py
@ -10,13 +10,14 @@ from sqlalchemy import (
|
|||||||
Float,
|
Float,
|
||||||
ForeignKey,
|
ForeignKey,
|
||||||
Integer,
|
Integer,
|
||||||
String
|
String,
|
||||||
|
func
|
||||||
)
|
)
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
from sqlalchemy.orm import relationship, sessionmaker
|
from sqlalchemy.orm import relationship, sessionmaker
|
||||||
|
|
||||||
from config import Config
|
from config import Config
|
||||||
from log import DEBUG, ERROR, INFO
|
from log import DEBUG, ERROR
|
||||||
|
|
||||||
# Create session at the global level as per
|
# Create session at the global level as per
|
||||||
# https://docs.sqlalchemy.org/en/13/orm/session_basics.html
|
# https://docs.sqlalchemy.org/en/13/orm/session_basics.html
|
||||||
@ -51,7 +52,7 @@ class Notes(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_note(playlist_id, row, text):
|
def add_note(playlist_id, row, text):
|
||||||
DEBUG(f"add_note({text})")
|
DEBUG(f"add_note(playlist_id={playlist_id}, row={row}, text={text})")
|
||||||
note = Notes()
|
note = Notes()
|
||||||
note.playlist_id = playlist_id
|
note.playlist_id = playlist_id
|
||||||
note.row = row
|
note.row = row
|
||||||
@ -62,7 +63,7 @@ class Notes(Base):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def update_note(cls, id, row, text):
|
def update_note(cls, id, row, text):
|
||||||
DEBUG(f"update_note({id}, {row}, {text})")
|
DEBUG(f"update_note(id={id}, row={row}, text={text})")
|
||||||
|
|
||||||
note = session.query(cls).filter(cls.id == id).one()
|
note = session.query(cls).filter(cls.id == id).one()
|
||||||
note.row = row
|
note.row = row
|
||||||
@ -80,7 +81,7 @@ class Playdates(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_playdate(track):
|
def add_playdate(track):
|
||||||
DEBUG(f"add_playdate({track})")
|
DEBUG(f"add_playdate(track={track})")
|
||||||
pd = Playdates()
|
pd = Playdates()
|
||||||
pd.lastplayed = datetime.now()
|
pd.lastplayed = datetime.now()
|
||||||
pd.track_id = track.id
|
pd.track_id = track.id
|
||||||
@ -148,7 +149,7 @@ class Playlists(Base):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def new(name):
|
def new(name):
|
||||||
DEBUG(f"Playlists.new({name})")
|
DEBUG(f"Playlists.new(name={name})")
|
||||||
pl = Playlists()
|
pl = Playlists()
|
||||||
pl.name = name
|
pl.name = name
|
||||||
session.add(pl)
|
session.add(pl)
|
||||||
@ -189,11 +190,26 @@ class PlaylistTracks(Base):
|
|||||||
tracks = relationship("Tracks", back_populates="playlists")
|
tracks = relationship("Tracks", back_populates="playlists")
|
||||||
playlists = relationship("Playlists", back_populates="tracks")
|
playlists = relationship("Playlists", back_populates="tracks")
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def new_row(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_track(playlist_id, track_id):
|
||||||
|
DEBUG(f"remove_track(playlist_id={playlist_id}, track_id={track_id})")
|
||||||
|
session.query(PlaylistTracks).filter(
|
||||||
|
PlaylistTracks.playlist_id == playlist_id,
|
||||||
|
PlaylistTracks.track_id == track_id
|
||||||
|
).delete()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update_track_row(playlist_id, track_id, old_row, new_row):
|
def update_track_row(playlist_id, track_id, old_row, new_row):
|
||||||
DEBUG(
|
DEBUG(
|
||||||
f"update_track_row({playlist_id}, "
|
f"update_track_row(playlist_id={playlist_id}, "
|
||||||
f"{track_id}, {old_row}, {new_row})"
|
f"track_id={track_id}, old_row={old_row}, new_row={new_row})"
|
||||||
)
|
)
|
||||||
|
|
||||||
plt = session.query(PlaylistTracks).filter(
|
plt = session.query(PlaylistTracks).filter(
|
||||||
@ -266,7 +282,7 @@ class Tracks(Base):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_or_create(cls, path):
|
def get_or_create(cls, path):
|
||||||
DEBUG(f"get_or_create(cls, {path})")
|
DEBUG(f"Tracks.get_or_create(path={path})")
|
||||||
try:
|
try:
|
||||||
track = session.query(cls).filter(cls.path == path).one()
|
track = session.query(cls).filter(cls.path == path).one()
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
@ -301,7 +317,7 @@ class Tracks(Base):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def get_track(id):
|
def get_track(id):
|
||||||
try:
|
try:
|
||||||
DEBUG(f"get_track({id})")
|
DEBUG(f"Tracks.get_track(track_id={id})")
|
||||||
track = session.query(Tracks).filter(Tracks.id == id).one()
|
track = session.query(Tracks).filter(Tracks.id == id).one()
|
||||||
return track
|
return track
|
||||||
except NoResultFound:
|
except NoResultFound:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user