first
This commit is contained in:
69
app/schemas/form.py
Normal file
69
app/schemas/form.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# app/schemas/form.py
|
||||
from pydantic import BaseModel, Field, validator
|
||||
from typing import Optional, List, Dict, Any
|
||||
from datetime import datetime
|
||||
from app.schemas.common import BaseSchema
|
||||
from app.schemas.field import FieldResponse
|
||||
|
||||
|
||||
class FormSettings(BaseModel):
|
||||
"""Настройки формы"""
|
||||
theme: Optional[str] = "light"
|
||||
show_submit_button: bool = True
|
||||
submit_button_text: str = "Submit"
|
||||
success_message: str = "Form submitted successfully"
|
||||
redirect_url: Optional[str] = None
|
||||
send_notifications: bool = False
|
||||
notification_emails: List[str] = Field(default_factory=list)
|
||||
limit_one_submission_per_user: bool = False
|
||||
enable_captcha: bool = False
|
||||
|
||||
|
||||
class FormCreate(BaseSchema):
|
||||
"""Создание формы"""
|
||||
name: str = Field(..., min_length=1, max_length=200)
|
||||
description: Optional[str] = Field(None, max_length=500)
|
||||
settings: FormSettings = Field(default_factory=FormSettings)
|
||||
fields: List[Dict[str, Any]] = Field(..., min_items=1)
|
||||
|
||||
@validator('name')
|
||||
def validate_name(cls, v):
|
||||
if not v.strip():
|
||||
raise ValueError('Name cannot be empty')
|
||||
return v.strip()
|
||||
|
||||
|
||||
class FormUpdate(BaseSchema):
|
||||
"""Обновление формы"""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=200)
|
||||
description: Optional[str] = None
|
||||
settings: Optional[FormSettings] = None
|
||||
is_active: Optional[bool] = None
|
||||
is_published: Optional[bool] = None
|
||||
|
||||
|
||||
class FormResponse(BaseSchema):
|
||||
"""Ответ с данными формы"""
|
||||
id: int
|
||||
name: str
|
||||
description: Optional[str]
|
||||
version: int
|
||||
is_active: bool
|
||||
is_published: bool
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
created_by: Optional[int]
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
|
||||
class FormWithFieldsResponse(FormResponse):
|
||||
"""Форма со всеми полями"""
|
||||
fields: List[FieldResponse] = Field(default_factory=list)
|
||||
|
||||
|
||||
class FormPublishRequest(BaseSchema):
|
||||
"""Публикация формы"""
|
||||
publish: bool = True
|
||||
version_note: Optional[str] = None
|
||||
Reference in New Issue
Block a user