Skip to content

Commit c6c8157

Browse files
authored
feat: custom login form class (#1634)
1 parent 0675040 commit c6c8157

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

docs/configuration/settings.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ UNFOLD = {
5757
"LOGIN": {
5858
"image": lambda request: static("sample/login-bg.jpg"),
5959
"redirect_after": lambda request: reverse_lazy("admin:APP_MODEL_changelist"),
60+
# Inherits from `unfold.forms.AuthenticationForm`
61+
"form": "app.forms.CustomLoginForm",
6062
},
6163
"STYLES": [
6264
lambda request: static("css/style.css"),

src/unfold/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
"LOGIN": {
8080
"image": None,
8181
"redirect_after": None,
82+
"form": None,
8283
},
8384
"EXTENSIONS": {"modeltranslation": {"flags": {}}},
8485
}

src/unfold/sites.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ def __init__(self, name: str = "admin") -> None:
4747

4848
super().__init__(name)
4949

50-
if self.login_form is None:
50+
custom_login_form = get_config(self.settings_name)["LOGIN"]["form"]
51+
52+
if custom_login_form is not None:
53+
self.login_form = import_string(custom_login_form)
54+
elif self.login_form is None:
5155
self.login_form = AuthenticationForm
5256

5357
def get_urls(self) -> list[URLPattern]:

0 commit comments

Comments
 (0)