cheesy/moku/forms/user.py

44 lines
1.4 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
class UserForm(UserCreationForm):
captcha = ReCaptchaField(required=True)
class Meta(UserCreationForm.Meta):
model = User
2024-03-25 11:58:42 +00:00
fields = ("username", "email", "password1", "password2")
2024-03-25 10:36:10 +00:00
labels = {
"username": _("username"),
"email": _("email address"),
2024-03-25 11:58:42 +00:00
"password1": _("password"),
"password2": _("password (again)"),
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,
2024-03-25 11:58:42 +00:00
"password1": _("make a secure password that you've never used before!"),
"password2": _("just type the password again to confirm"),
2024-03-25 10:36:10 +00:00
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["captcha"].error_messages = {"required": _("make sure you've ticked the captcha.")}
class ProfileForm(forms.ModelForm):
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"),
}