File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1717from django .utils .safestring import mark_safe
1818from django .utils .translation import gettext_lazy as _
1919
20- from .widgets import BASE_INPUT_CLASSES , INPUT_CLASSES , SELECT_CLASSES
20+ from .widgets import (
21+ BASE_INPUT_CLASSES ,
22+ INPUT_CLASSES ,
23+ SELECT_CLASSES ,
24+ UnfoldAdminPasswordInput ,
25+ UnfoldAdminRadioSelectWidget ,
26+ )
2127
2228
2329class UnfoldReadOnlyPasswordHashWidget (ReadOnlyPasswordHashWidget ):
@@ -65,8 +71,17 @@ def __init__(
6571 ) -> None :
6672 super ().__init__ (request , * args , ** kwargs )
6773
68- self .fields ["password1" ].widget .attrs ["class" ] = " " .join (INPUT_CLASSES )
69- self .fields ["password2" ].widget .attrs ["class" ] = " " .join (INPUT_CLASSES )
74+ self .fields ["password1" ].widget = UnfoldAdminPasswordInput (
75+ attrs = {"autocomplete" : "new-password" }
76+ )
77+ self .fields ["password2" ].widget = UnfoldAdminPasswordInput (
78+ attrs = {"autocomplete" : "new-password" }
79+ )
80+
81+ if "usable_password" in self .fields :
82+ self .fields ["usable_password" ].widget = UnfoldAdminRadioSelectWidget (
83+ choices = self .fields ["usable_password" ].choices ,
84+ )
7085
7186
7287class UserChangeForm (BaseUserChangeForm ):
Original file line number Diff line number Diff line change 2323 MultiWidget ,
2424 NullBooleanSelect ,
2525 NumberInput ,
26+ PasswordInput ,
2627 Select ,
2728)
2829from django .utils .translation import gettext_lazy as _
@@ -566,3 +567,10 @@ def __init__(
566567 ** (attrs or {}),
567568 }
568569 super ().__init__ (rel , admin_site , attrs , using )
570+
571+
572+ class UnfoldAdminPasswordInput (PasswordInput ):
573+ def __init__ (self , attrs = None , render_value = False ):
574+ super ().__init__ (
575+ {"class" : " " .join (INPUT_CLASSES ), ** (attrs or {})}, render_value
576+ )
You can’t perform that action at this time.
0 commit comments