123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- from django import forms
- from django.utils.translation import gettext_lazy as _
- from ....admin.forms import YesNoSwitch
- from ... import settings
- from .base import ChangeSettingsForm
- class ChangeUsersSettingsForm(ChangeSettingsForm):
- settings = [
- "account_activation",
- "allow_custom_avatars",
- "avatar_upload_limit",
- "default_avatar",
- "default_gravatar_fallback",
- "blank_avatar",
- "signature_length_max",
- "subscribe_reply",
- "subscribe_start",
- "username_length_max",
- "username_length_min",
- ]
- account_activation = forms.ChoiceField(
- label=_("Require new accounts activation"),
- choices=[
- ("none", _("No activation required")),
- ("user", _("Activation token sent to user e-mail")),
- ("admin", _("Activation by administrator")),
- ("closed", _("Disable new registrations")),
- ],
- widget=forms.RadioSelect(),
- )
- username_length_min = forms.IntegerField(
- label=_("Minimum allowed username length"), min_value=2, max_value=20
- )
- username_length_max = forms.IntegerField(
- label=_("Maximum allowed username length"), min_value=2, max_value=20
- )
- allow_custom_avatars = YesNoSwitch(
- label=_("Allow custom avatar uploads"),
- help_text=_(
- "Turning this option off will forbid forum users from uploading custom "
- "avatars. Good for forums adressed at young users."
- ),
- )
- avatar_upload_limit = forms.IntegerField(
- label=_("Maximum size of uploaded avatar"),
- help_text=_("Enter maximum allowed file size (in KB) for avatar uploads."),
- min_value=0,
- )
- default_avatar = forms.ChoiceField(
- label=_("Default avatar"),
- choices=[
- ("dynamic", _("Individual")),
- ("gravatar", _("Gravatar")),
- ("gallery", _("Random avatar from gallery")),
- ],
- widget=forms.RadioSelect(),
- )
- default_gravatar_fallback = forms.ChoiceField(
- label=_("Fallback for default gravatar"),
- help_text=_(
- "Select which avatar to use when user has no gravatar associated with "
- "their e-mail address."
- ),
- choices=[
- ("dynamic", _("Individual")),
- ("gallery", _("Random avatar from gallery")),
- ],
- widget=forms.RadioSelect(),
- )
- blank_avatar = forms.ImageField(
- label=_("Blank avatar"),
- help_text=_(
- "Blank avatar is displayed in the interface when user's avatar is not "
- "available: when user was deleted or is guest. Uploaded image should be "
- "a square"
- ),
- required=False,
- )
- blank_avatar_delete = forms.BooleanField(
- label=_("Delete custom blank avatar"), required=False
- )
- signature_length_max = forms.IntegerField(
- label=_("Maximum allowed signature length"), min_value=10, max_value=5000
- )
- subscribe_start = forms.ChoiceField(
- label=_("Started threads"),
- choices=[
- ("no", _("Don't watch")),
- ("watch", _("Put on watched threads list")),
- (
- "watch_email",
- _("Put on watched threads list and e-mail user when somebody replies"),
- ),
- ],
- widget=forms.RadioSelect(),
- )
- subscribe_reply = forms.ChoiceField(
- label=_("Replied threads"),
- choices=[
- ("no", _("Don't watch")),
- ("watch", _("Put on watched threads list")),
- (
- "watch_email",
- _("Put on watched threads list and e-mail user when somebody replies"),
- ),
- ],
- widget=forms.RadioSelect(),
- )
- def clean_blank_avatar(self):
- upload = self.cleaned_data.get("blank_avatar")
- if not upload or upload == self.initial.get("blank_avatar"):
- return None
- if upload.image.width != upload.image.height:
- raise forms.ValidationError(_("Submitted image is not a square."))
- min_size = max(settings.MISAGO_AVATARS_SIZES)
- if upload.image.width < min_size:
- raise forms.ValidationError(
- _("Submitted image's edge should be at least %(size)s pixels long.")
- % {"size": min_size}
- )
- return upload
|