2023-02-20 11:41:29 +03:00
|
|
|
"""Module containing WTForms classes
|
|
|
|
and helper functions for Starlette-WTF"""
|
|
|
|
|
|
|
|
from typing import Type, TypeVar
|
|
|
|
|
|
|
|
from fastapi import Request
|
|
|
|
from starlette_wtf import StarletteForm
|
|
|
|
|
|
|
|
T = TypeVar('T', bound=StarletteForm)
|
|
|
|
|
|
|
|
|
|
|
|
async def get_form(
|
|
|
|
form: Type[T],
|
|
|
|
req: Request) -> T:
|
|
|
|
"""Almost the same as `form.from_formdata`,
|
2023-02-22 20:39:50 +03:00
|
|
|
and must be used *instead* of instantiating
|
|
|
|
form object directly as in Flask.
|
|
|
|
See `respond.with_tmpl` for explanation
|
|
|
|
about the `request` argument
|
2023-02-20 11:41:29 +03:00
|
|
|
|
|
|
|
Args:
|
|
|
|
form (Type[StarletteForm]): StarletteForm class
|
|
|
|
req (Request): Request object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
StarletteForm instance
|
|
|
|
"""
|
|
|
|
|
|
|
|
return await form.from_formdata(request=req)
|