Refactor settings system and improve context initialization
Backend: - Add type validation and coercion for settings API - Implement SettingStorage and SettingType in registry - Improve CRUD operations for settings Frontend: - Refactor Theme, Language, Sidebar, ViewMode contexts - Simplify admin components (GeneralTab, SettingsTab, UsersTab) - Add new settings endpoints to API client - Improve App initialization flow Infrastructure: - Update Dockerfile and docker-compose.yml - Add .dockerignore - Update Makefile and README 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -71,7 +71,7 @@ class CRUDBase(Generic[ModelType, CreateSchemaType, UpdateSchemaType]):
|
||||
|
||||
def delete(self, db: Session, *, id: Any) -> ModelType:
|
||||
"""Delete a record."""
|
||||
obj = db.query(self.model).get(id)
|
||||
obj = db.get(self.model, id)
|
||||
db.delete(obj)
|
||||
db.commit()
|
||||
return obj
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""CRUD operations for Settings."""
|
||||
|
||||
import json
|
||||
from typing import Optional
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
@@ -27,13 +28,16 @@ def update_setting(db: Session, key: str, value: any) -> Settings:
|
||||
setting = Settings(key=key)
|
||||
db.add(setting)
|
||||
|
||||
# Determine if value is bool or string
|
||||
# Determine how to store the value (DB has only bool + string columns)
|
||||
if isinstance(value, bool):
|
||||
setting.value_bool = value
|
||||
setting.value_str = None
|
||||
elif isinstance(value, str) and value.lower() in ('true', 'false'):
|
||||
setting.value_bool = value.lower() == 'true'
|
||||
elif isinstance(value, str) and value.lower() in ("true", "false", "1", "0"):
|
||||
setting.value_bool = value.lower() in ("true", "1")
|
||||
setting.value_str = None
|
||||
elif isinstance(value, (dict, list)):
|
||||
setting.value_str = json.dumps(value)
|
||||
setting.value_bool = None
|
||||
else:
|
||||
setting.value_str = str(value)
|
||||
setting.value_bool = None
|
||||
|
||||
Reference in New Issue
Block a user