From d79c78e53037ab8bd6b99382fca044bd9d39c161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Mon, 27 Jul 2026 10:02:43 +0400 Subject: [PATCH] =?UTF-8?q?v1.0.52:=20=5Ftmpl()=20helper=20=E2=80=94=20all?= =?UTF-8?q?=20template=20vars=20in=20all=20code=20paths=20(fix=20Undefined?= =?UTF-8?q?Error)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- site/app.py | 2 +- site/routes/main.py | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/site/app.py b/site/app.py index fc542df..342a0b8 100644 --- a/site/app.py +++ b/site/app.py @@ -6,7 +6,7 @@ from routes.main import bp as main_bp from routes.api import bp as api_bp from routes.api_test import bp as api_test_bp -VERSION = "1.0.51" +VERSION = "1.0.52" app = Flask(__name__, template_folder="templates", static_folder="static") app.config["NUBES_API_ENDPOINT"] = os.getenv("NUBES_API_ENDPOINT", "https://lk-api-gateway-dev.ngcloud.ru/api/v1/svc") diff --git a/site/routes/main.py b/site/routes/main.py index 3efc0ac..c4cd262 100644 --- a/site/routes/main.py +++ b/site/routes/main.py @@ -70,13 +70,31 @@ def index(): org = None error = None + services = [] + instances = [] + instance_groups = {} + config = {} action = request.form.get("action", "") + def _tmpl(**overrides): + """Собрать контекст шаблона со всеми обязательными переменными.""" + ctx = { + "organization": org, + "error": error, + "env_token_masked": _mask(env_token), + "has_user_token": bool(user_token), + "client_id": _client_id(active_token), + "token_info": _token_info(active_token), + "config": config, + "services": services, + "instances": instances, + "instance_groups": instance_groups, + } + ctx.update(overrides) + return render_template("index.html", **ctx) + if action == "clear": - resp = make_response(render_template("index.html", - organization=None, error=None, - env_token_masked=_mask(env_token), - has_user_token=False)) + resp = make_response(_tmpl(organization=None, error=None, has_user_token=False)) resp.delete_cookie("token") return resp @@ -121,13 +139,7 @@ def index(): else: error = "Токен невалиден или просрочен" - return render_template("index.html", - organization=org, error=error, - env_token_masked=_mask(env_token), - has_user_token=bool(user_token), - client_id=_client_id(active_token), - token_info=_token_info(active_token), - instance_groups=instance_groups) + return _tmpl() @bp.route("/api/operations/")