mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-07-11 15:22:55 +02:00
feat: add form for user settings
This commit is contained in:
+26
-11
@@ -1,25 +1,18 @@
|
|||||||
from crispy_forms.bootstrap import (
|
from crispy_forms.bootstrap import (
|
||||||
FormActions,
|
FormActions,
|
||||||
PrependedText,
|
|
||||||
Alert,
|
|
||||||
)
|
)
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
from crispy_forms.layout import Layout, Submit, Div, HTML
|
from crispy_forms.layout import Layout, Submit
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth import get_user_model
|
|
||||||
from django.contrib.auth.forms import (
|
from django.contrib.auth.forms import (
|
||||||
# AuthenticationForm,
|
|
||||||
UsernameField,
|
UsernameField,
|
||||||
PasswordResetForm,
|
|
||||||
SetPasswordForm,
|
|
||||||
PasswordChangeForm,
|
|
||||||
UserCreationForm,
|
|
||||||
AuthenticationForm,
|
AuthenticationForm,
|
||||||
)
|
)
|
||||||
from django.core.exceptions import ValidationError
|
|
||||||
from django.utils.safestring import mark_safe
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from apps.common.widgets.crispy.submit import NoClassSubmit
|
||||||
|
from apps.users.models import UserSettings
|
||||||
|
|
||||||
|
|
||||||
class LoginForm(AuthenticationForm):
|
class LoginForm(AuthenticationForm):
|
||||||
username = UsernameField(
|
username = UsernameField(
|
||||||
@@ -50,3 +43,25 @@ class LoginForm(AuthenticationForm):
|
|||||||
"password",
|
"password",
|
||||||
Submit("Submit", "Login"),
|
Submit("Submit", "Login"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class UserSettingsForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = UserSettings
|
||||||
|
fields = ["language", "timezone"]
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
|
self.helper = FormHelper()
|
||||||
|
self.helper.form_tag = False
|
||||||
|
self.helper.form_method = "post"
|
||||||
|
self.helper.layout = Layout(
|
||||||
|
"language",
|
||||||
|
"timezone",
|
||||||
|
FormActions(
|
||||||
|
NoClassSubmit(
|
||||||
|
"submit", _("Save"), css_class="btn btn-outline-primary w-100"
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user