2024-03-25 10:36:10 +00:00
|
|
|
from django import forms
|
|
|
|
|
from django.contrib.auth.forms import UserCreationForm
|
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
|
from django_recaptcha.fields import ReCaptchaField
|
|
|
|
|
|
2024-03-27 16:52:06 +00:00
|
|
|
from moku.models.user import User
|
2024-03-25 10:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserForm(UserCreationForm):
|
2024-03-26 12:44:19 +00:00
|
|
|
"""Form for creating a new user account on the site."""
|
|
|
|
|
|
2024-03-25 10:36:10 +00:00
|
|
|
captcha = ReCaptchaField(required=True)
|
2024-03-25 18:48:00 +00:00
|
|
|
check = forms.BooleanField(required=True)
|
2024-03-25 10:36:10 +00:00
|
|
|
|
|
|
|
|
class Meta(UserCreationForm.Meta):
|
|
|
|
|
model = User
|
2024-03-25 11:58:42 +00:00
|
|
|
fields = ("username", "email", "password1", "password2")
|
2024-03-26 12:18:47 +00:00
|
|
|
labels = {"username": _("username"), "email": _("email address")}
|
2024-03-25 10:36:10 +00:00
|
|
|
help_texts = {
|
|
|
|
|
"username": User._meta.get_field("username").help_text,
|
|
|
|
|
"email": User._meta.get_field("email").help_text,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super().__init__(*args, **kwargs)
|
2024-03-25 18:48:00 +00:00
|
|
|
self.fields["captcha"].error_messages = {
|
2024-03-26 12:18:47 +00:00
|
|
|
"required": _("make sure you've ticked the captcha.")
|
2024-03-25 18:48:00 +00:00
|
|
|
}
|
|
|
|
|
self.fields["check"].error_messages = {
|
2024-03-26 12:18:47 +00:00
|
|
|
"required": _("you must agree to the terms of use and privacy policy.")
|
2024-03-25 18:48:00 +00:00
|
|
|
}
|
2024-03-25 10:36:10 +00:00
|
|
|
|
|
|
|
|
|
2024-03-25 17:12:36 +00:00
|
|
|
class UserSettingsForm(forms.ModelForm):
|
2024-03-26 12:44:19 +00:00
|
|
|
"""Form for creating or updating user settings."""
|
|
|
|
|
|
2024-03-25 17:12:36 +00:00
|
|
|
class Meta:
|
2024-03-27 16:52:06 +00:00
|
|
|
model = User
|
2024-03-25 17:12:36 +00:00
|
|
|
fields = ("language",)
|
2024-03-26 12:18:47 +00:00
|
|
|
labels = {"language": _("language")}
|
2024-03-25 17:12:36 +00:00
|
|
|
|
|
|
|
|
|
2024-03-25 10:36:10 +00:00
|
|
|
class ProfileForm(forms.ModelForm):
|
2024-03-26 12:44:19 +00:00
|
|
|
"""Form for updating user profile information."""
|
|
|
|
|
|
2024-03-25 10:36:10 +00:00
|
|
|
class Meta:
|
|
|
|
|
model = User
|
2024-03-25 14:11:21 +00:00
|
|
|
fields = ("avatar", "pronouns", "location", "bio")
|
2024-03-25 10:36:10 +00:00
|
|
|
labels = {
|
2024-03-25 14:11:21 +00:00
|
|
|
"avatar": _("avatar"),
|
2024-03-25 10:36:10 +00:00
|
|
|
"pronouns": _("pronouns"),
|
|
|
|
|
"location": _("location"),
|
|
|
|
|
"bio": _("about me"),
|
|
|
|
|
}
|