Skip to content

Commit 3445287

Browse files
authored
fix: user create form (#522)
1 parent 668bba1 commit 3445287

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/unfold/forms.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@
1717
from django.utils.safestring import mark_safe
1818
from 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

2329
class 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

7287
class UserChangeForm(BaseUserChangeForm):

src/unfold/widgets.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
MultiWidget,
2424
NullBooleanSelect,
2525
NumberInput,
26+
PasswordInput,
2627
Select,
2728
)
2829
from 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+
)

0 commit comments

Comments
 (0)