-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_settings.py
More file actions
82 lines (59 loc) · 2.56 KB
/
user_settings.py
File metadata and controls
82 lines (59 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from datetime import datetime, timezone
from typing import Any
from beanie import Document, Indexed
from pydantic import BaseModel, ConfigDict, Field
from app.domain.enums import NotificationChannel, Theme
class NotificationSettings(BaseModel):
"""User notification preferences (embedded document)."""
model_config = ConfigDict(from_attributes=True)
execution_completed: bool = True
execution_failed: bool = True
system_updates: bool = True
security_alerts: bool = True
channels: list[NotificationChannel] = [NotificationChannel.IN_APP]
class EditorSettings(BaseModel):
"""Code editor preferences (embedded document)."""
model_config = ConfigDict(from_attributes=True)
font_size: int = 14
tab_size: int = 4
use_tabs: bool = False
word_wrap: bool = True
show_line_numbers: bool = True
class UserSettingsDocument(Document):
"""Complete user settings model."""
user_id: Indexed(str, unique=True) # type: ignore[valid-type]
theme: Theme = Theme.AUTO
timezone: str = "UTC"
date_format: str = "YYYY-MM-DD"
time_format: str = "24h"
notifications: NotificationSettings = Field(default_factory=NotificationSettings)
editor: EditorSettings = Field(default_factory=EditorSettings)
custom_settings: dict[str, Any] = Field(default_factory=dict)
version: int = 1
created_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
updated_at: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
model_config = ConfigDict(from_attributes=True)
class Settings:
name = "user_settings"
use_state_management = True
class UserSettingsSnapshotDocument(Document):
"""Snapshot of user settings for history/restore.
Based on UserSettings with additional snapshot metadata.
"""
user_id: Indexed(str) # type: ignore[valid-type]
snapshot_at: Indexed(datetime) = Field(default_factory=lambda: datetime.now(timezone.utc)) # type: ignore[valid-type]
# Full settings snapshot
theme: Theme = Theme.AUTO
timezone: str = "UTC"
date_format: str = "YYYY-MM-DD"
time_format: str = "24h"
notifications: NotificationSettings = Field(default_factory=NotificationSettings)
editor: EditorSettings = Field(default_factory=EditorSettings)
custom_settings: dict[str, Any] = Field(default_factory=dict)
version: int = 1
# Snapshot metadata
reason: str | None = None
model_config = ConfigDict(from_attributes=True)
class Settings:
name = "user_settings_snapshots"
use_state_management = True