2023-02-20 12:41:29 +04: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 21:39:50 +04: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 12:41:29 +04:00
|
|
|
|
|
|
|
Args:
|
|
|
|
form (Type[StarletteForm]): StarletteForm class
|
|
|
|
req (Request): Request object
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
StarletteForm instance
|
|
|
|
"""
|
2023-02-27 19:05:57 +04:00
|
|
|
|
2023-02-20 12:41:29 +04:00
|
|
|
return await form.from_formdata(request=req)
|