From 1d5bfed5567c4223be7276165cd56873be6cad90 Mon Sep 17 00:00:00 2001 From: richard-dds Date: Mon, 19 Nov 2018 11:46:21 -0500 Subject: [PATCH] Exactract "formCache' into form_cache.PARAM_NAME --- atst/routes/__init__.py | 6 ++++-- atst/routes/errors.py | 2 +- atst/utils/form_cache.py | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/atst/routes/__init__.py b/atst/routes/__init__.py index 0ea12952..214fb35c 100644 --- a/atst/routes/__init__.py +++ b/atst/routes/__init__.py @@ -97,8 +97,10 @@ def _make_authentication_context(): def redirect_after_login_url(): if request.args.get("next"): returl = request.args.get("next") - if request.args.get("formCache"): - returl += "?" + url.urlencode({"formCache": request.args.get("formCache")}) + if request.args.get(app.form_cache.PARAM_NAME): + returl += "?" + url.urlencode( + {app.form_cache.PARAM_NAME: request.args.get(app.form_cache.PARAM_NAME)} + ) return returl else: return url_for("atst.home") diff --git a/atst/routes/errors.py b/atst/routes/errors.py index 039ae635..3f32b110 100644 --- a/atst/routes/errors.py +++ b/atst/routes/errors.py @@ -39,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"] = app.form_cache.write(request.form) + url_args[app.form_cache.PARAM_NAME] = app.form_cache.write(request.form) return redirect(url_for("atst.root", **url_args)) @app.errorhandler(Exception) diff --git a/atst/utils/form_cache.py b/atst/utils/form_cache.py index 3ce4f17a..c7ac6d80 100644 --- a/atst/utils/form_cache.py +++ b/atst/utils/form_cache.py @@ -7,11 +7,13 @@ DEFAULT_CACHE_NAME = "formcache" class FormCache(object): + PARAM_NAME = "formCache" + def __init__(self, redis): self.redis = redis def from_request(self, http_request): - cache_key = http_request.args.get("formCache") + cache_key = http_request.args.get(self.PARAM_NAME) if cache_key: return self.read(cache_key)