Files
disknext/sqlmodels/theme_preset.py
于小丘 6c96c43bea
Some checks failed
Test / test (push) Failing after 3m47s
refactor: 统一 sqlmodel_ext 用法至官方推荐模式
- 替换 Field(max_length=X) 为 StrX/TextX 类型别名(21 个 sqlmodels 文件)
- 替换 get + 404 检查为 get_exist_one()(17 个路由文件,约 50 处)
- 替换 save + session.refresh 为 save(load=...)
- 替换 session.add + commit 为 save()(dav/provider.py)
- 更新所有依赖至最新版本

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 11:13:16 +08:00

118 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from datetime import datetime
from uuid import UUID
from sqlmodel import Field
from sqlmodel_ext import SQLModelBase, UUIDTableBaseMixin, Str100
from .color import ChromaticColor, NeutralColor, ThemeColorsBase
class ThemePresetBase(SQLModelBase):
"""主题预设基础字段"""
name: Str100
"""预设名称"""
is_default: bool = False
"""是否为默认预设"""
primary: ChromaticColor
"""主色调"""
secondary: ChromaticColor
"""辅助色"""
success: ChromaticColor
"""成功色"""
info: ChromaticColor
"""信息色"""
warning: ChromaticColor
"""警告色"""
error: ChromaticColor
"""错误色"""
neutral: NeutralColor
"""中性色"""
class ThemePreset(ThemePresetBase, UUIDTableBaseMixin):
"""主题预设表"""
name: Str100 = Field(unique=True)
"""预设名称(唯一约束)"""
# ==================== DTO ====================
class ThemePresetCreateRequest(SQLModelBase):
"""创建主题预设请求 DTO"""
name: Str100
"""预设名称"""
colors: ThemeColorsBase
"""颜色配置"""
class ThemePresetUpdateRequest(SQLModelBase):
"""更新主题预设请求 DTO"""
name: Str100 | None = None
"""预设名称(可选)"""
colors: ThemeColorsBase | None = None
"""颜色配置(可选)"""
class ThemePresetResponse(SQLModelBase):
"""主题预设响应 DTO"""
id: UUID
"""预设UUID"""
name: str
"""预设名称"""
is_default: bool
"""是否为默认预设"""
colors: ThemeColorsBase
"""颜色配置"""
created_at: datetime
"""创建时间"""
updated_at: datetime
"""更新时间"""
@classmethod
def from_preset(cls, preset: ThemePreset) -> 'ThemePresetResponse':
"""从数据库模型转换为响应 DTO平铺列 → 嵌套 colors 对象)"""
return cls(
id=preset.id,
name=preset.name,
is_default=preset.is_default,
colors=ThemeColorsBase(
primary=preset.primary,
secondary=preset.secondary,
success=preset.success,
info=preset.info,
warning=preset.warning,
error=preset.error,
neutral=preset.neutral,
),
created_at=preset.created_at,
updated_at=preset.updated_at,
)
class ThemePresetListResponse(SQLModelBase):
"""主题预设列表响应 DTO"""
themes: list[ThemePresetResponse]
"""主题预设列表"""