From c84483424a16c6dba2d3331f90da27fa63185861 Mon Sep 17 00:00:00 2001 From: NikDizell Date: Tue, 24 Feb 2026 00:13:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=90=D0=B2=D1=82=D0=BE=20=D0=B8=D0=B7=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | 3 +- static/admin/css/unusable_password_field.css | 19 +++++++++++++ static/admin/img/icon-hidelink.svg | 3 ++ static/admin/js/unusable_password_field.js | 29 ++++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 static/admin/css/unusable_password_field.css create mode 100644 static/admin/img/icon-hidelink.svg create mode 100644 static/admin/js/unusable_password_field.js diff --git a/requirements.txt b/requirements.txt index e4e932d..d53766c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,4 +4,5 @@ whitenoise==6.5.0 Pillow==10.0.0 psycopg2-binary==2.9.7 django-bootstrap5==23.3 -django-extensions==3.2.3 \ No newline at end of file +django-extensions==3.2.3 +python-dotenv>=1.0.0 \ No newline at end of file diff --git a/static/admin/css/unusable_password_field.css b/static/admin/css/unusable_password_field.css new file mode 100644 index 0000000..d46eb03 --- /dev/null +++ b/static/admin/css/unusable_password_field.css @@ -0,0 +1,19 @@ +/* Hide warnings fields if usable password is selected */ +form:has(#id_usable_password input[value="true"]:checked) .messagelist { + display: none; +} + +/* Hide password fields if unusable password is selected */ +form:has(#id_usable_password input[value="false"]:checked) .field-password1, +form:has(#id_usable_password input[value="false"]:checked) .field-password2 { + display: none; +} + +/* Select appropriate submit button */ +form:has(#id_usable_password input[value="true"]:checked) input[type="submit"].unset-password { + display: none; +} + +form:has(#id_usable_password input[value="false"]:checked) input[type="submit"].set-password { + display: none; +} diff --git a/static/admin/img/icon-hidelink.svg b/static/admin/img/icon-hidelink.svg new file mode 100644 index 0000000..2a8b404 --- /dev/null +++ b/static/admin/img/icon-hidelink.svg @@ -0,0 +1,3 @@ + + + diff --git a/static/admin/js/unusable_password_field.js b/static/admin/js/unusable_password_field.js new file mode 100644 index 0000000..ec26238 --- /dev/null +++ b/static/admin/js/unusable_password_field.js @@ -0,0 +1,29 @@ +"use strict"; +// Fallback JS for browsers which do not support :has selector used in +// admin/css/unusable_password_fields.css +// Remove file once all supported browsers support :has selector +try { + // If browser does not support :has selector this will raise an error + document.querySelector("form:has(input)"); +} catch (error) { + console.log("Defaulting to javascript for usable password form management: " + error); + // JS replacement for unsupported :has selector + document.querySelectorAll('input[name="usable_password"]').forEach(option => { + option.addEventListener('change', function() { + const usablePassword = (this.value === "true" ? this.checked : !this.checked); + const submit1 = document.querySelector('input[type="submit"].set-password'); + const submit2 = document.querySelector('input[type="submit"].unset-password'); + const messages = document.querySelector('#id_unusable_warning'); + document.getElementById('id_password1').closest('.form-row').hidden = !usablePassword; + document.getElementById('id_password2').closest('.form-row').hidden = !usablePassword; + if (messages) { + messages.hidden = usablePassword; + } + if (submit1 && submit2) { + submit1.hidden = !usablePassword; + submit2.hidden = usablePassword; + } + }); + option.dispatchEvent(new Event('change')); + }); +}