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