Files
aurum/backend/app/core/config.py
ZProger 75dd43c8e3 feat: manual theme picker (light/dark/system) in Settings
Theme previously followed only the OS's prefers-color-scheme, which
switches automatically on this user's Mac at sunset/sunrise. Adds an
explicit override in Settings: Light/Dark/System, System being the
previous (default) auto-follow-the-OS behavior.

Persisted client-side in localStorage (lib/theme.ts, same pattern as
language) rather than server-side like currency — it's a pure display
preference, and synchronous localStorage reads are what make the
anti-FOUC inline script in index.html possible. index.css already had the
[data-theme] CSS variables laid in ahead of time; only the JS to actually
set the attribute, and the Settings UI, were missing.

Covered by 2 new Playwright specs (theme-switcher.spec.ts) run against the
isolated e2e stack: explicit choice overrides a dark OS and survives
reload; switching back to "system" doesn't leave a stale forced theme.
2026-08-16 23:12:20 +03:00

45 lines
1.4 KiB
Python

"""Application configuration, sourced from environment variables (.env)."""
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
# Single source of truth for the running app's version — surfaced in the API
# title and embedded in exported backups so an old file can be told apart
# from a current one.
APP_VERSION = "0.19.0"
class Settings(BaseSettings):
model_config = SettingsConfigDict(env_file=".env", env_prefix="AURUM_", extra="ignore")
# Postgres connection
postgres_user: str = "aurum"
postgres_password: str = "aurum"
postgres_db: str = "aurum"
postgres_host: str = "db"
postgres_port: int = 5432
# Default currency shown across the UI when an account doesn't override it
default_currency: str = "USD"
# Comma-separated list of origins allowed to call the API (frontend dev server, etc.)
cors_origins: str = "*"
@property
def database_url(self) -> str:
return (
f"postgresql+asyncpg://{self.postgres_user}:{self.postgres_password}"
f"@{self.postgres_host}:{self.postgres_port}/{self.postgres_db}"
)
@property
def cors_origins_list(self) -> list[str]:
if self.cors_origins == "*":
return ["*"]
return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()]
@lru_cache
def get_settings() -> Settings:
return Settings()