cheesy/moku/forms/user.py

55 lines
1.7 KiB
Python
Raw Normal View History

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
from moku.models.user import User, UserSettings
2024-03-25 10:36:10 +00:00
class UserForm(UserCreationForm):
"""Form for creating a new user account on the site."""
2024-03-25 10:36:10 +00:00
captcha = ReCaptchaField(required=True)
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)
self.fields["captcha"].error_messages = {
2024-03-26 12:18:47 +00:00
"required": _("make sure you've ticked the captcha.")
}
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 10:36:10 +00:00
class UserSettingsForm(forms.ModelForm):
"""Form for creating or updating user settings."""
class Meta:
model = UserSettings
fields = ("language",)
2024-03-26 12:18:47 +00:00
labels = {"language": _("language")}
2024-03-25 10:36:10 +00:00
class ProfileForm(forms.ModelForm):
"""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"),
}