From dd4bec33291884a4914738b3d4c5b94a2d463b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 8 Oct 2015 13:49:57 +0200 Subject: [PATCH] Fix: Do not cache templates if wizards are active Otherwise wizards will be reshown until the cache is forcefully cleared. --- src/octoprint/server/views.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py index 6ec2337f..0dafccfc 100644 --- a/src/octoprint/server/views.py +++ b/src/octoprint/server/views.py @@ -33,10 +33,16 @@ _valid_div_re = re.compile("[a-zA-Z_-]+") @app.route("/") def index(): - force_refresh = util.flask.cache_check_headers() or "_refresh" in request.values - global _templates, _plugin_names, _plugin_vars + # helper to check if wizards are active + def wizard_active(templates): + return templates is not None and bool(templates["wizard"]["order"]) + + # we force a refresh if the client forces one or if we have wizards cached + force_refresh = util.flask.cache_check_headers() or "_refresh" in request.values or wizard_active(_templates) + + # if we need to refresh our template cache or it's not yet set, process it if force_refresh or _templates is None or _plugin_names is None or _plugin_vars is None: _templates, _plugin_names, _plugin_vars = _process_templates() @@ -58,9 +64,8 @@ def index(): break else: - wizard = bool(_templates["wizard"]["order"]) + wizard = wizard_active(_templates) enable_accesscontrol = userManager is not None - render_kwargs.update(dict( webcamStream=settings().get(["webcam", "stream"]), enableTemperatureGraph=settings().get(["feature", "temperatureGraph"]), @@ -75,7 +80,8 @@ def index(): # no plugin took an interest, we'll use the default UI def make_default_ui(): r = make_response(render_template("index.jinja2", **render_kwargs)) - if bool(render_kwargs["templates"]["wizard"]["order"]): + if wizard: + # if we have active wizard dialogs, set non caching headers r = util.flask.add_non_caching_response_headers(r) return r