Forms
AirForm
AirForm(initial_data=None)
A form handler that validates incoming form data against a Pydantic model. To be used with FastAPI's dependency injection system.
class CheeseModel(pydantic.BaseModel):
name: str
age: int
class CheeseForm(air.AirForm):
model = CheeseModel
@app.post("/cheese")
async def cheese_form(cheese: Annotated[CheeseForm, Depends(CheeseForm())]):
if cheese.is_valid:
return air.Html(air.H1(cheese.data.name))
return air.Html(air.H1(air.Raw(str(len(cheese.errors)))))
NOTE: This is named AirForm to avoid collisions with tags.Form
Source code in src/air/forms.py
44 45 46 47 |
|
widget
property
widget
Widget for rendering of form in HTML
If you want a custom widget, replace with a function that accepts:
- model: BaseModel
- data: dict|None
- errors:dict|None=None
AirField
AirField(default=None, *, type=None, label=None, default_factory=None, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, multiple_of=None, min_length=None, max_length=None, pattern=None, max_digits=None, decimal_places=None, examples=None, deprecated=None, exclude=False, discriminator=None, frozen=None, validate_default=None, repr=True, init_var=None, kw_only=None, json_schema_extra=None, **extra)
A wrapper around pydantic.Field to provide a cleaner interface for defining special input types and labels in air forms.
NOTE: This is named AirField to adhere to the same naming convention as AirForm.
Source code in src/air/forms.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
errors_to_dict
errors_to_dict(errors)
Converts a pydantic error list to a dictionary for easier reference.
Source code in src/air/forms.py
112 113 114 115 116 |
|
pydantic_type_to_html_type
pydantic_type_to_html_type(field_info)
Return HTML type from pydantic type.
Default to 'text' for unknown types.
Source code in src/air/forms.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|