chore(home): mirror from kalinamall (9883e6a) with papatramp URLs
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.ui_settings import UI_SETTINGS_ROW_ID, UiSettings
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class UiSettingsConfig:
|
||||
show_sidebar_system_stats: bool
|
||||
source: str = "db"
|
||||
|
||||
|
||||
def get_effective_ui_settings(db: Session) -> UiSettingsConfig:
|
||||
row = db.get(UiSettings, UI_SETTINGS_ROW_ID)
|
||||
if row is None:
|
||||
return UiSettingsConfig(show_sidebar_system_stats=True, source="default")
|
||||
return UiSettingsConfig(show_sidebar_system_stats=bool(row.show_sidebar_system_stats), source="db")
|
||||
|
||||
|
||||
def upsert_ui_settings(db: Session, *, show_sidebar_system_stats: bool) -> UiSettingsConfig:
|
||||
row = db.get(UiSettings, UI_SETTINGS_ROW_ID)
|
||||
if row is None:
|
||||
row = UiSettings(id=UI_SETTINGS_ROW_ID, show_sidebar_system_stats=show_sidebar_system_stats)
|
||||
db.add(row)
|
||||
else:
|
||||
row.show_sidebar_system_stats = show_sidebar_system_stats
|
||||
db.commit()
|
||||
db.refresh(row)
|
||||
return get_effective_ui_settings(db)
|
||||
Reference in New Issue
Block a user