Use FormCache

This commit is contained in:
richard-dds 2018-11-16 11:38:58 -05:00
parent cd4a5df2d6
commit 6177f46587
2 changed files with 3 additions and 3 deletions

View File

@ -8,7 +8,6 @@ from atst.domain.invitations import (
ExpiredError as InvitationExpiredError,
WrongUserError as InvitationWrongUserError,
)
from atst.utils.form_cache import cache_form_data
def log_error(e):
@ -40,7 +39,7 @@ def make_error_pages(app):
log_error(e)
url_args = {"sessionExpired": True, "next": request.path}
if request.method == "POST":
url_args["formCache"] = cache_form_data(app.redis, request.form)
url_args["formCache"] = app.form_cache.write(request.form)
return redirect(url_for("atst.root", **url_args))
@app.errorhandler(Exception)

View File

@ -32,10 +32,11 @@ class FormCache(object):
value = pickle.dumps(formdata)
hash_ = hashlib.sha1(os.urandom(64)).hexdigest()
self.redis.setex(name=self._key(key_prefix, hash_), value=value, time=expiry_seconds)
return hash_
def read(self, formdata_key, key_prefix="formcache"):
data = self.redis.get(self._key(key_prefix, formdata_key))
return pickle.loads(data)
return pickle.loads(data) if data is not None else {}
@staticmethod
def _key(prefix, hash_):