mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-09 20:05:20 -05:00
refactor schema folders
This commit is contained in:
6
mealie/schema/admin/__init__.py
Normal file
6
mealie/schema/admin/__init__.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from .about import *
|
||||
from .backup import *
|
||||
from .migration import *
|
||||
from .restore import *
|
||||
from .settings import *
|
||||
from .theme import *
|
||||
25
mealie/schema/admin/about.py
Normal file
25
mealie/schema/admin/about.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from pathlib import Path
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
|
||||
|
||||
class AppStatistics(CamelModel):
|
||||
total_recipes: int
|
||||
total_users: int
|
||||
total_groups: int
|
||||
uncategorized_recipes: int
|
||||
untagged_recipes: int
|
||||
|
||||
|
||||
class AppInfo(CamelModel):
|
||||
production: bool
|
||||
version: str
|
||||
demo_status: bool
|
||||
|
||||
|
||||
class DebugInfo(AppInfo):
|
||||
api_port: int
|
||||
api_docs: bool
|
||||
db_type: str
|
||||
db_url: Path
|
||||
default_group: str
|
||||
81
mealie/schema/admin/backup.py
Normal file
81
mealie/schema/admin/backup.py
Normal file
@@ -0,0 +1,81 @@
|
||||
from datetime import datetime
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class BackupOptions(BaseModel):
|
||||
recipes: bool = True
|
||||
settings: bool = True
|
||||
pages: bool = True
|
||||
themes: bool = True
|
||||
groups: bool = True
|
||||
users: bool = True
|
||||
notifications: bool = True
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"recipes": True,
|
||||
"settings": True,
|
||||
"themes": True,
|
||||
"groups": True,
|
||||
"users": True,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class ImportJob(BackupOptions):
|
||||
name: str
|
||||
force: bool = False
|
||||
rebase: bool = False
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"name": "my_local_backup.zip",
|
||||
"recipes": True,
|
||||
"settings": True,
|
||||
"themes": True,
|
||||
"groups": True,
|
||||
"users": True,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class BackupJob(BaseModel):
|
||||
tag: Optional[str]
|
||||
options: BackupOptions
|
||||
templates: Optional[List[str]]
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"tag": "July 23rd 2021",
|
||||
"options": BackupOptions(),
|
||||
"template": ["recipes.md"],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class LocalBackup(BaseModel):
|
||||
name: str
|
||||
date: datetime
|
||||
|
||||
|
||||
class Imports(BaseModel):
|
||||
imports: List[LocalBackup]
|
||||
templates: List[str]
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"imports": [
|
||||
{
|
||||
"name": "AutoBackup_12-1-2020.zip",
|
||||
"date": datetime.now(),
|
||||
}
|
||||
],
|
||||
"templates": ["recipes.md", "custom_template.md"],
|
||||
}
|
||||
}
|
||||
31
mealie/schema/admin/migration.py
Normal file
31
mealie/schema/admin/migration.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from datetime import datetime
|
||||
from typing import List
|
||||
|
||||
from pydantic.main import BaseModel
|
||||
|
||||
from .restore import RecipeImport
|
||||
|
||||
|
||||
class ChowdownURL(BaseModel):
|
||||
url: str
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"url": "https://chowdownrepo.com/repo",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class MigrationFile(BaseModel):
|
||||
name: str
|
||||
date: datetime
|
||||
|
||||
|
||||
class Migrations(BaseModel):
|
||||
type: str
|
||||
files: List[MigrationFile] = []
|
||||
|
||||
|
||||
class MigrationImport(RecipeImport):
|
||||
pass
|
||||
37
mealie/schema/admin/restore.py
Normal file
37
mealie/schema/admin/restore.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic.main import BaseModel
|
||||
|
||||
|
||||
class ImportBase(BaseModel):
|
||||
name: str
|
||||
status: bool
|
||||
exception: Optional[str]
|
||||
|
||||
|
||||
class RecipeImport(ImportBase):
|
||||
slug: Optional[str]
|
||||
|
||||
|
||||
class ThemeImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class SettingsImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class GroupImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class UserImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class CustomPageImport(ImportBase):
|
||||
pass
|
||||
|
||||
|
||||
class NotificationImport(ImportBase):
|
||||
pass
|
||||
58
mealie/schema/admin/settings.py
Normal file
58
mealie/schema/admin/settings.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import Optional
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import validator
|
||||
from slugify import slugify
|
||||
|
||||
from ..recipe.category import CategoryBase, RecipeCategoryResponse
|
||||
|
||||
|
||||
class SiteSettings(CamelModel):
|
||||
language: str = "en-US"
|
||||
first_day_of_week: int = 0
|
||||
show_recent: bool = True
|
||||
cards_per_section: int = 9
|
||||
categories: Optional[list[CategoryBase]] = []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"language": "en",
|
||||
"firstDayOfWeek": 0,
|
||||
"showRecent": True,
|
||||
"categories": [
|
||||
{"id": 1, "name": "thanksgiving", "slug": "thanksgiving"},
|
||||
{"id": 2, "name": "homechef", "slug": "homechef"},
|
||||
{"id": 3, "name": "potatoes", "slug": "potatoes"},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CustomPageBase(CamelModel):
|
||||
name: str
|
||||
slug: Optional[str]
|
||||
position: int
|
||||
categories: list[RecipeCategoryResponse] = []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@validator("slug", always=True, pre=True)
|
||||
def validate_slug(slug: str, values):
|
||||
name: str = values["name"]
|
||||
calc_slug: str = slugify(name)
|
||||
|
||||
if slug != calc_slug:
|
||||
slug = calc_slug
|
||||
|
||||
return slug
|
||||
|
||||
|
||||
class CustomPageOut(CustomPageBase):
|
||||
id: int
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
39
mealie/schema/admin/theme.py
Normal file
39
mealie/schema/admin/theme.py
Normal file
@@ -0,0 +1,39 @@
|
||||
from typing import Optional
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Colors(BaseModel):
|
||||
primary: str = "#E58325"
|
||||
accent: str = "#00457A"
|
||||
secondary: str = "#973542"
|
||||
success: str = "#43A047"
|
||||
info: str = "#1976D2"
|
||||
warning: str = "#FF6F00"
|
||||
error: str = "#EF5350"
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class SiteTheme(BaseModel):
|
||||
id: Optional[int]
|
||||
name: str = "default"
|
||||
colors: Colors = Colors()
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"name": "default",
|
||||
"colors": {
|
||||
"primary": "#E58325",
|
||||
"accent": "#00457A",
|
||||
"secondary": "#973542",
|
||||
"success": "#5AB1BB",
|
||||
"info": "#4990BA",
|
||||
"warning": "#FF4081",
|
||||
"error": "#EF5350",
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user