From 393aecb8f16d7c881cf27697111436c324516aa6 Mon Sep 17 00:00:00 2001 From: catborise Date: Mon, 2 Nov 2026 08:47:58 +0300 Subject: [PATCH] refactor(templates): the shared page scripts load from static files A step towards a Content-Security-Policy without inline scripts. The scripts every page or many pages share now load from static files: the error focus of base.html, the please-wait dialog, the sign-in forms' password toggle and busy button, the jobs pages' reload while a job runs, and the start of the job panel and of the VM list's state poll, whose values come as json_script data. Cancel links go back through a data-history-back attribute instead of a javascript: URL. The IE8 html5shiv/respond.js block, X-UA-Compatible and shrink-to-fit are gone: no supported browser reads them. --- .../accounts/change_password_form.html | 2 +- .../templates/accounts/email_otp_form.html | 2 +- accounts/templates/accounts/otp_login.html | 31 ++--------------- accounts/templates/login.html | 31 ++--------------- .../templates/instances/vm_states_poll.html | 2 +- instances/tests/test_page_controls.py | 2 +- instances/tests/test_xss.py | 2 -- operations/static/operations/follow_active.js | 6 ++++ .../static/operations/job_panel_start.js | 9 +++++ .../templates/operations/follow_active.html | 9 ++--- .../operations/job_panel_script.html | 9 ++--- operations/templatetags/operations.py | 12 +++++-- static/js/back_links.js | 7 ++++ static/js/error_focus.js | 20 +++++++++++ static/js/login_form.js | 19 +++++++++++ static/js/please_wait.js | 15 +++++++++ static/js/vm_states_start.js | 2 ++ templates/base.html | 33 ++----------------- templates/common/confirm_delete.html | 2 +- templates/common/form.html | 2 +- templates/error.html | 2 +- templates/pleasewaitdialog.html | 19 ++--------- webvirtcloud/tests/test_error_focus.py | 11 ++----- 23 files changed, 112 insertions(+), 137 deletions(-) create mode 100644 operations/static/operations/follow_active.js create mode 100644 operations/static/operations/job_panel_start.js create mode 100644 static/js/back_links.js create mode 100644 static/js/error_focus.js create mode 100644 static/js/login_form.js create mode 100644 static/js/please_wait.js create mode 100644 static/js/vm_states_start.js diff --git a/accounts/templates/accounts/change_password_form.html b/accounts/templates/accounts/change_password_form.html index 046447e8..406fbab9 100644 --- a/accounts/templates/accounts/change_password_form.html +++ b/accounts/templates/accounts/change_password_form.html @@ -21,7 +21,7 @@
- {% trans "Cancel" %} + {% trans "Cancel" %}
diff --git a/templates/common/form.html b/templates/common/form.html index b08aaadd..1a6112d4 100644 --- a/templates/common/form.html +++ b/templates/common/form.html @@ -19,7 +19,7 @@
{% bootstrap_form form %}
- {% trans "Cancel" %} + {% trans "Cancel" %}
diff --git a/templates/error.html b/templates/error.html index d360274e..1bfb489a 100644 --- a/templates/error.html +++ b/templates/error.html @@ -23,7 +23,7 @@
- + {% trans "Back" %} diff --git a/templates/pleasewaitdialog.html b/templates/pleasewaitdialog.html index 448ab277..1a9a1951 100644 --- a/templates/pleasewaitdialog.html +++ b/templates/pleasewaitdialog.html @@ -1,4 +1,4 @@ -{% load i18n %} +{% load i18n static %}
- + diff --git a/webvirtcloud/tests/test_error_focus.py b/webvirtcloud/tests/test_error_focus.py index 27e847ce..307fefe0 100644 --- a/webvirtcloud/tests/test_error_focus.py +++ b/webvirtcloud/tests/test_error_focus.py @@ -1,9 +1,8 @@ -"""After a refused submission the page starts at the error: base.html's -script focuses the first visible invalid field, else the error message. +"""After a refused submission the page starts at the error: error_focus.js +focuses the first visible invalid field, else the error message. The script runs in Node against a stand-in document.""" import json -import re import shutil import subprocess import unittest @@ -11,11 +10,7 @@ from pathlib import Path from django.conf import settings -SCRIPT = re.search( - r"", - Path(settings.BASE_DIR, "templates/base.html").read_text(), - re.S, -).group(1) +SCRIPT = Path(settings.BASE_DIR, "static/js/error_focus.js").read_text() HARNESS = """ const els = %s;