28 lines
859 B
Python
28 lines
859 B
Python
|
|
"""Pydantic schemas for contact form."""
|
||
|
|
|
||
|
|
from pydantic import BaseModel, EmailStr, Field, model_validator
|
||
|
|
|
||
|
|
|
||
|
|
class ContactCreate(BaseModel):
|
||
|
|
"""Contact form input schema."""
|
||
|
|
|
||
|
|
name: str = Field(..., min_length=1, max_length=255)
|
||
|
|
email: EmailStr
|
||
|
|
phone: str | None = Field(None, max_length=64)
|
||
|
|
message: str = Field(..., min_length=1, max_length=5000)
|
||
|
|
privacy_consent: bool = Field(..., description="Must be True")
|
||
|
|
|
||
|
|
@model_validator(mode="after")
|
||
|
|
def consent_must_be_true(self) -> "ContactCreate":
|
||
|
|
"""Reject submissions where privacy_consent is not True."""
|
||
|
|
if not self.privacy_consent:
|
||
|
|
raise ValueError("privacy_consent must be True")
|
||
|
|
return self
|
||
|
|
|
||
|
|
|
||
|
|
class ContactResponse(BaseModel):
|
||
|
|
"""Contact form response."""
|
||
|
|
|
||
|
|
success: bool
|
||
|
|
message: str = "Kontakt-Anfrage erfolgreich gesendet."
|