Black changes
This commit is contained in:
parent
8fa98a2207
commit
bf5563f2f1
71
app/ds.py
71
app/ds.py
@ -44,8 +44,8 @@ from models import (
|
|||||||
|
|
||||||
# Configure the dogpile cache region
|
# Configure the dogpile cache region
|
||||||
cache_region = make_region().configure(
|
cache_region = make_region().configure(
|
||||||
'dogpile.cache.memory', # Use in-memory caching for now (switch to Redis if needed)
|
"dogpile.cache.memory", # Use in-memory caching for now (switch to Redis if needed)
|
||||||
expiration_time=600 # Cache expires after 10 minutes
|
expiration_time=600, # Cache expires after 10 minutes
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -179,7 +179,9 @@ def notecolours_remove_colour_substring(text: str) -> str:
|
|||||||
|
|
||||||
# Track functions
|
# Track functions
|
||||||
# @log_call
|
# @log_call
|
||||||
def _tracks_where(query: BinaryExpression | ColumnElement[bool],) -> list[TrackDTO]:
|
def _tracks_where(
|
||||||
|
query: BinaryExpression | ColumnElement[bool],
|
||||||
|
) -> list[TrackDTO]:
|
||||||
"""
|
"""
|
||||||
filter_by_last_played: bool = False,
|
filter_by_last_played: bool = False,
|
||||||
last_played_before: dt.datetime | None = None,
|
last_played_before: dt.datetime | None = None,
|
||||||
@ -435,9 +437,7 @@ def tracks_filtered(filter: Filter) -> list[TrackDTO]:
|
|||||||
|
|
||||||
|
|
||||||
# @log_call
|
# @log_call
|
||||||
def track_update(
|
def track_update(track_id: int, metadata: dict[str, str | int | float]) -> TrackDTO:
|
||||||
track_id: int, metadata: dict[str, str | int | float]
|
|
||||||
) -> TrackDTO:
|
|
||||||
"""
|
"""
|
||||||
Update an existing track db entry return the DTO
|
Update an existing track db entry return the DTO
|
||||||
"""
|
"""
|
||||||
@ -523,13 +523,17 @@ def _playlists_where(
|
|||||||
Return playlists selected by query
|
Return playlists selected by query
|
||||||
"""
|
"""
|
||||||
|
|
||||||
stmt = select(
|
stmt = (
|
||||||
Playlists.favourite,
|
select(
|
||||||
Playlists.is_template,
|
Playlists.favourite,
|
||||||
Playlists.id.label("playlist_id"),
|
Playlists.is_template,
|
||||||
Playlists.name,
|
Playlists.id.label("playlist_id"),
|
||||||
Playlists.open,
|
Playlists.name,
|
||||||
).where(query).order_by(Playlists.tab)
|
Playlists.open,
|
||||||
|
)
|
||||||
|
.where(query)
|
||||||
|
.order_by(Playlists.tab)
|
||||||
|
)
|
||||||
|
|
||||||
results: list[PlaylistDTO] = []
|
results: list[PlaylistDTO] = []
|
||||||
|
|
||||||
@ -597,7 +601,9 @@ def playlists_closed() -> list[PlaylistDTO]:
|
|||||||
|
|
||||||
|
|
||||||
# @log_call
|
# @log_call
|
||||||
def playlist_create(name: str, template_id: int, as_template: bool = False) -> PlaylistDTO:
|
def playlist_create(
|
||||||
|
name: str, template_id: int, as_template: bool = False
|
||||||
|
) -> PlaylistDTO:
|
||||||
"""
|
"""
|
||||||
Create playlist and return DTO.
|
Create playlist and return DTO.
|
||||||
"""
|
"""
|
||||||
@ -676,9 +682,7 @@ def playlist_mark_status(playlist_id: int, open: bool) -> None:
|
|||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
session.execute(
|
session.execute(
|
||||||
update(Playlists)
|
update(Playlists).where(Playlists.id == playlist_id).values(open=open)
|
||||||
.where(Playlists.id == playlist_id)
|
|
||||||
.values(open=open)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -791,9 +795,7 @@ def playlist_rename(playlist_id: int, new_name: str) -> None:
|
|||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
session.execute(
|
session.execute(
|
||||||
update(Playlists)
|
update(Playlists).where(Playlists.id == playlist_id).values(name=new_name)
|
||||||
.where(Playlists.id == playlist_id)
|
|
||||||
.values(name=new_name)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
session.commit()
|
session.commit()
|
||||||
@ -919,11 +921,9 @@ def playlist_save_tabs(playlist_id_to_tab: dict[int, int]) -> None:
|
|||||||
.where(Playlists.id.in_(playlist_id_to_tab.keys()))
|
.where(Playlists.id.in_(playlist_id_to_tab.keys()))
|
||||||
.values(tab=None)
|
.values(tab=None)
|
||||||
)
|
)
|
||||||
for (playlist_id, tab) in playlist_id_to_tab.items():
|
for playlist_id, tab in playlist_id_to_tab.items():
|
||||||
session.execute(
|
session.execute(
|
||||||
update(Playlists)
|
update(Playlists).where(Playlists.id == playlist_id).values(tab=tab)
|
||||||
.where(Playlists.id == playlist_id)
|
|
||||||
.values(tab=tab)
|
|
||||||
)
|
)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@ -943,6 +943,7 @@ def playlist_update_template_favourite(template_id: int, favourite: bool) -> Non
|
|||||||
|
|
||||||
# Playlist Rows
|
# Playlist Rows
|
||||||
|
|
||||||
|
|
||||||
# @log_call
|
# @log_call
|
||||||
def playlistrow_by_id(playlistrow_id: int) -> PlaylistRowDTO | None:
|
def playlistrow_by_id(playlistrow_id: int) -> PlaylistRowDTO | None:
|
||||||
"""
|
"""
|
||||||
@ -951,7 +952,9 @@ def playlistrow_by_id(playlistrow_id: int) -> PlaylistRowDTO | None:
|
|||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
record = (
|
record = (
|
||||||
session.execute(select(PlaylistRows).where(PlaylistRows.id == playlistrow_id))
|
session.execute(
|
||||||
|
select(PlaylistRows).where(PlaylistRows.id == playlistrow_id)
|
||||||
|
)
|
||||||
.scalars()
|
.scalars()
|
||||||
.one_or_none()
|
.one_or_none()
|
||||||
)
|
)
|
||||||
@ -977,9 +980,7 @@ def playlistrow_by_id(playlistrow_id: int) -> PlaylistRowDTO | None:
|
|||||||
def playlistrows_by_playlist(
|
def playlistrows_by_playlist(
|
||||||
playlist_id: int, check_playlist_itegrity: bool = True
|
playlist_id: int, check_playlist_itegrity: bool = True
|
||||||
) -> list[PlaylistRowDTO]:
|
) -> list[PlaylistRowDTO]:
|
||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
|
|
||||||
# TODO: would be good to be confident at removing this
|
# TODO: would be good to be confident at removing this
|
||||||
if check_playlist_itegrity:
|
if check_playlist_itegrity:
|
||||||
_playlist_check_playlist(
|
_playlist_check_playlist(
|
||||||
@ -994,7 +995,6 @@ def playlistrows_by_playlist(
|
|||||||
|
|
||||||
dto_list = []
|
dto_list = []
|
||||||
for record in records:
|
for record in records:
|
||||||
|
|
||||||
track = None
|
track = None
|
||||||
if record.track_id:
|
if record.track_id:
|
||||||
track = track_by_id(record.track_id)
|
track = track_by_id(record.track_id)
|
||||||
@ -1040,7 +1040,9 @@ def playlistrow_played(playlistrow_id: int, status: bool) -> None:
|
|||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
session.execute(
|
session.execute(
|
||||||
update(PlaylistRows).where(PlaylistRows.id == playlistrow_id).values(played=status)
|
update(PlaylistRows)
|
||||||
|
.where(PlaylistRows.id == playlistrow_id)
|
||||||
|
.values(played=status)
|
||||||
)
|
)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
@ -1096,10 +1098,7 @@ def playdates_between_dates(
|
|||||||
Playdates.lastplayed,
|
Playdates.lastplayed,
|
||||||
Playdates.track_id,
|
Playdates.track_id,
|
||||||
Playdates.track,
|
Playdates.track,
|
||||||
).where(
|
).where(Playdates.lastplayed >= start, Playdates.lastplayed <= end)
|
||||||
Playdates.lastplayed >= start,
|
|
||||||
Playdates.lastplayed <= end
|
|
||||||
)
|
|
||||||
|
|
||||||
results: list[PlaydatesDTO] = []
|
results: list[PlaydatesDTO] = []
|
||||||
|
|
||||||
@ -1137,10 +1136,7 @@ def _queries_where(
|
|||||||
results: list[QueryDTO] = []
|
results: list[QueryDTO] = []
|
||||||
|
|
||||||
with db.Session() as session:
|
with db.Session() as session:
|
||||||
records = session.scalars(
|
records = session.scalars(select(Queries).where(query)).all()
|
||||||
select(Queries)
|
|
||||||
.where(query)
|
|
||||||
).all()
|
|
||||||
for record in records:
|
for record in records:
|
||||||
dto = QueryDTO(
|
dto = QueryDTO(
|
||||||
favourite=record.favourite,
|
favourite=record.favourite,
|
||||||
@ -1273,4 +1269,3 @@ def db_name_get() -> str:
|
|||||||
dbname = session.bind.engine.url.database
|
dbname = session.bind.engine.url.database
|
||||||
return dbname
|
return dbname
|
||||||
return Config.DB_NOT_FOUND
|
return Config.DB_NOT_FOUND
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user