Black changes

This commit is contained in:
Keith Edmunds 2025-04-16 10:23:17 +01:00
parent 8fa98a2207
commit bf5563f2f1

View File

@ -44,8 +44,8 @@ from models import (
# Configure the dogpile cache region
cache_region = make_region().configure(
'dogpile.cache.memory', # Use in-memory caching for now (switch to Redis if needed)
expiration_time=600 # Cache expires after 10 minutes
"dogpile.cache.memory", # Use in-memory caching for now (switch to Redis if needed)
expiration_time=600, # Cache expires after 10 minutes
)
@ -179,7 +179,9 @@ def notecolours_remove_colour_substring(text: str) -> str:
# Track functions
# @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,
last_played_before: dt.datetime | None = None,
@ -435,9 +437,7 @@ def tracks_filtered(filter: Filter) -> list[TrackDTO]:
# @log_call
def track_update(
track_id: int, metadata: dict[str, str | int | float]
) -> TrackDTO:
def track_update(track_id: int, metadata: dict[str, str | int | float]) -> TrackDTO:
"""
Update an existing track db entry return the DTO
"""
@ -523,13 +523,17 @@ def _playlists_where(
Return playlists selected by query
"""
stmt = select(
Playlists.favourite,
Playlists.is_template,
Playlists.id.label("playlist_id"),
Playlists.name,
Playlists.open,
).where(query).order_by(Playlists.tab)
stmt = (
select(
Playlists.favourite,
Playlists.is_template,
Playlists.id.label("playlist_id"),
Playlists.name,
Playlists.open,
)
.where(query)
.order_by(Playlists.tab)
)
results: list[PlaylistDTO] = []
@ -597,7 +601,9 @@ def playlists_closed() -> list[PlaylistDTO]:
# @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.
"""
@ -676,9 +682,7 @@ def playlist_mark_status(playlist_id: int, open: bool) -> None:
with db.Session() as session:
session.execute(
update(Playlists)
.where(Playlists.id == playlist_id)
.values(open=open)
update(Playlists).where(Playlists.id == playlist_id).values(open=open)
)
session.commit()
@ -791,9 +795,7 @@ def playlist_rename(playlist_id: int, new_name: str) -> None:
with db.Session() as session:
session.execute(
update(Playlists)
.where(Playlists.id == playlist_id)
.values(name=new_name)
update(Playlists).where(Playlists.id == playlist_id).values(name=new_name)
)
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()))
.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(
update(Playlists)
.where(Playlists.id == playlist_id)
.values(tab=tab)
update(Playlists).where(Playlists.id == playlist_id).values(tab=tab)
)
session.commit()
@ -943,6 +943,7 @@ def playlist_update_template_favourite(template_id: int, favourite: bool) -> Non
# Playlist Rows
# @log_call
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:
record = (
session.execute(select(PlaylistRows).where(PlaylistRows.id == playlistrow_id))
session.execute(
select(PlaylistRows).where(PlaylistRows.id == playlistrow_id)
)
.scalars()
.one_or_none()
)
@ -977,9 +980,7 @@ def playlistrow_by_id(playlistrow_id: int) -> PlaylistRowDTO | None:
def playlistrows_by_playlist(
playlist_id: int, check_playlist_itegrity: bool = True
) -> list[PlaylistRowDTO]:
with db.Session() as session:
# TODO: would be good to be confident at removing this
if check_playlist_itegrity:
_playlist_check_playlist(
@ -994,7 +995,6 @@ def playlistrows_by_playlist(
dto_list = []
for record in records:
track = None
if 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:
session.execute(
update(PlaylistRows).where(PlaylistRows.id == playlistrow_id).values(played=status)
update(PlaylistRows)
.where(PlaylistRows.id == playlistrow_id)
.values(played=status)
)
session.commit()
@ -1096,10 +1098,7 @@ def playdates_between_dates(
Playdates.lastplayed,
Playdates.track_id,
Playdates.track,
).where(
Playdates.lastplayed >= start,
Playdates.lastplayed <= end
)
).where(Playdates.lastplayed >= start, Playdates.lastplayed <= end)
results: list[PlaydatesDTO] = []
@ -1137,10 +1136,7 @@ def _queries_where(
results: list[QueryDTO] = []
with db.Session() as session:
records = session.scalars(
select(Queries)
.where(query)
).all()
records = session.scalars(select(Queries).where(query)).all()
for record in records:
dto = QueryDTO(
favourite=record.favourite,
@ -1273,4 +1269,3 @@ def db_name_get() -> str:
dbname = session.bind.engine.url.database
return dbname
return Config.DB_NOT_FOUND