Automatically use cached form data

This commit is contained in:
richard-dds
2018-11-19 14:30:24 -05:00
parent 1d5bfed556
commit 26cd9b4cb0
4 changed files with 22 additions and 15 deletions

View File

@@ -1,7 +1,8 @@
from flask_wtf import FlaskForm
from flask import current_app, request as http_request
class ValidatedForm(FlaskForm):
class _ValidatedForm(FlaskForm):
def perform_extra_validation(self, *args, **kwargs):
"""Performs any applicable extra validation. Must
return True if the form is valid or False otherwise."""
@@ -12,3 +13,11 @@ class ValidatedForm(FlaskForm):
_data = super().data
_data.pop("csrf_token", None)
return _data
class ValidatedForm(_ValidatedForm):
def __init__(self, formdata=None, **kwargs):
formdata = formdata or {}
cached_data = current_app.form_cache.from_request(http_request)
cached_data.update(formdata)
super().__init__(cached_data, **kwargs)