Skip to content

Commit

Permalink
fix: user form types (#764)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasvinclav authored Sep 23, 2024
1 parent af58552 commit 1f0c108
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/unfold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from django.contrib.auth.forms import (
AdminPasswordChangeForm as BaseAdminPasswordChangeForm,
)
from django.contrib.auth.models import User

try:
from django.contrib.auth.forms import AdminUserCreationForm as BaseUserCreationForm
Expand Down Expand Up @@ -70,11 +71,10 @@ def __init__(
class UserCreationForm(BaseUserCreationForm):
def __init__(
self,
request: Optional[HttpRequest] = None,
*args,
**kwargs,
) -> None:
super().__init__(request, *args, **kwargs)
super().__init__(*args, **kwargs)

self.fields["password1"].widget = UnfoldAdminPasswordInput(
attrs={"autocomplete": "new-password"}
Expand All @@ -92,11 +92,10 @@ def __init__(
class UserChangeForm(BaseUserChangeForm):
def __init__(
self,
request: Optional[HttpRequest] = None,
*args,
**kwargs,
) -> None:
super().__init__(request, *args, **kwargs)
super().__init__(*args, **kwargs)
self.fields["password"].widget = UnfoldReadOnlyPasswordHashWidget()

self.fields["password"].help_text = _(
Expand All @@ -113,19 +112,19 @@ def __init__(
class AdminPasswordChangeForm(BaseAdminPasswordChangeForm):
def __init__(
self,
request: Optional[HttpRequest] = None,
user: User,
*args,
**kwargs,
) -> None:
super().__init__(request, *args, **kwargs)
super().__init__(user, *args, **kwargs)

self.fields["password1"].widget.attrs["class"] = " ".join(INPUT_CLASSES)
self.fields["password2"].widget.attrs["class"] = " ".join(INPUT_CLASSES)


class AdminOwnPasswordChangeForm(BaseAdminOwnPasswordChangeForm):
def __init__(self, *args, **kwargs) -> None:
super().__init__(kwargs.pop("user"), *args, **kwargs)
def __init__(self, user: User, *args, **kwargs) -> None:
super().__init__(user, *args, **kwargs)

self.fields["old_password"].widget.attrs["class"] = " ".join(INPUT_CLASSES)
self.fields["new_password1"].widget.attrs["class"] = " ".join(INPUT_CLASSES)
Expand Down

0 comments on commit 1f0c108

Please sign in to comment.