class BanUsersForm(forms.Form): ban_type = forms.MultipleChoiceField( label=_("Values to ban"), widget=forms.CheckboxSelectMultiple, choices=(('usernames', _('Usernames')), ('emails', _('E-mails')), ('domains', _('E-mail domains')), ('ip', _('IP addresses')), ('ip_first', _('First segment of IP addresses')), ('ip_two', _('First two segments of IP addresses')))) user_message = forms.CharField( label=_("User message"), required=False, max_length=1000, help_text=_("Optional message displayed to users " "instead of default one."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) staff_message = forms.CharField( label=_("Team message"), required=False, max_length=1000, help_text=_("Optional ban message for moderators and administrators."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) expires_on = forms.IsoDateTimeField( label=_("Expires on"), required=False, help_text=_('Leave this field empty for set bans to never expire.'))
class ModerateAvatarForm(forms.ModelForm): is_avatar_locked = forms.YesNoSwitch( label=_("Lock avatar"), help_text=_("Setting this to yes will stop user from " "changing his/her avatar, and will reset " "his/her avatar to procedurally generated one.")) avatar_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message for user explaining " "why he/she is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) avatar_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message for forum team members explaining " "why user is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) class Meta: model = get_user_model() fields = [ 'is_avatar_locked', 'avatar_lock_user_message', 'avatar_lock_staff_message', ]
class BanForm(forms.Form): user_message = forms.CharField( label=_("User message"), required=False, max_length=1000, help_text=_("Optional message displayed to user " "instead of default one."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) staff_message = forms.CharField( label=_("Team message"), required=False, max_length=1000, help_text=_("Optional ban message for moderators and administrators."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) expires_on = forms.DateTimeField( label=_("Expires on"), required=False, localize=True, help_text=_('Leave this field empty for this ban to never expire.')) def __init__(self, *args, **kwargs): self.user = kwargs.pop('user') super(BanForm, self).__init__(*args, **kwargs) if self.user.acl_['max_ban_length']: message = ungettext( "Required. Can't be longer than %(days)s day.", "Required. Can't be longer than %(days)s days.", self.user.acl_['max_ban_length']) message = message % {'days': self.user.acl_['max_ban_length']} self['expires_on'].field.help_text = message def clean_expires_on(self): data = self.cleaned_data['expires_on'] if self.user.acl_['max_ban_length']: max_ban_length = timedelta(days=self.user.acl_['max_ban_length']) if not data or data > (timezone.now() + max_ban_length).date(): message = ungettext( "You can't set bans longer than %(days)s day.", "You can't set bans longer than %(days)s days.", self.user.acl_['max_ban_length']) message = message % {'days': self.user.acl_['max_ban_length']} raise forms.ValidationError(message) elif data and data < timezone.now().date(): raise forms.ValidationError(_("Expiration date is in past.")) return data def ban_user(self): ban_user(self.user, user_message=self.cleaned_data['user_message'], staff_message=self.cleaned_data['staff_message'], expires_on=self.cleaned_data['expires_on'])
class BanForm(forms.ModelForm): test = forms.TypedChoiceField(label=_("Ban type"), coerce=int, choices=BANS_CHOICES) banned_value = forms.CharField( label=_("Banned value"), max_length=250, help_text=_('This value is case-insensitive and accepts asterisk (*) ' 'for rought matches. For example, making IP ban for value ' '"83.*" will ban all IP addresses beginning with "83.".'), error_messages={ 'max_length': _("Banned value can't be longer " "than 250 characters.") }) user_message = forms.CharField( label=_("User message"), required=False, max_length=1000, help_text=_("Optional message displayed instead of default one."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) staff_message = forms.CharField( label=_("Team message"), required=False, max_length=1000, help_text=_("Optional ban message for moderators and administrators."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) valid_until = forms.DateField( label=_("Expiration date"), required=False, input_formats=['%m-%d-%Y'], widget=forms.DateInput(format='%m-%d-%Y', attrs={'data-date-format': 'MM-DD-YYYY'}), help_text=_('Leave this field empty for this ban to never expire.')) class Meta: model = Ban fields = [ 'test', 'banned_value', 'user_message', 'staff_message', 'valid_until', ] def clean_banned_value(self): data = self.cleaned_data['banned_value'] while '**' in data: data = data.replace('**', '*') if data == '*': raise forms.ValidationError(_("Banned value is too vague.")) return data
class RankForm(forms.ModelForm): name = forms.CharField( label=_("Name"), validators=[validate_sluggable()], help_text=_('Short and descriptive name of all users with this rank. ' '"The Team" or "Game Masters" are good examples.')) title = forms.CharField( label=_("User title"), required=False, help_text=_('Optional, singular version of rank name displayed by ' 'user names. For example "GM" or "Dev".')) description = forms.CharField( label=_("Description"), max_length=2048, required=False, widget=forms.Textarea(attrs={'rows': 3}), help_text=_("Optional description explaining function or status of " "members distincted with this rank.")) roles = forms.ModelMultipleChoiceField( label=_("User roles"), queryset=Role.objects.order_by('name'), required=False, widget=forms.CheckboxSelectMultiple, help_text=_('Rank can give additional roles to users with it.')) css_class = forms.CharField( label=_("CSS class"), required=False, help_text=_("Optional css class added to content belonging to this " "rank owner.")) is_tab = forms.BooleanField( label=_("Give rank dedicated tab on users list"), required=False, help_text=_("Selecting this option will make users with this rank " "easily discoverable by others trough dedicated page on " "forum users list.")) is_on_index = forms.BooleanField( label=_("Show users online on forum index"), required=False, help_text=_("Selecting this option will make forum inform other " "users of their availability by displaying them on forum " "index page.")) class Meta: model = Rank fields = [ 'name', 'description', 'css_class', 'title', 'roles', 'is_tab', 'is_on_index', ] def clean(self): data = super(RankForm, self).clean() self.instance.set_name(data.get('name')) return data
def create_textarea(setting, kwargs, extra): widget_kwargs = {} if extra.get('min_length', 0) == 0: kwargs['required'] = False if extra.get('rows', 0): widget_kwargs['attrs'] = {'rows': extra.pop('rows')} kwargs['widget'] = forms.Textarea(**widget_kwargs) return forms.CharField(**kwargs)
class ModerateSignatureForm(forms.ModelForm): signature = forms.CharField( label=_("Signature contents"), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_signature_locked = forms.YesNoSwitch( label=_("Lock signature"), help_text=_("Setting this to yes will stop user from " "making changes to his/her signature.")) signature_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message to user explaining " "why his/hers signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message to team members explaining " "why user signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) class Meta: model = get_user_model() fields = [ 'signature', 'is_signature_locked', 'signature_lock_user_message', 'signature_lock_staff_message' ] def clean_signature(self): data = self.cleaned_data['signature'] length_limit = settings.signature_length_max if len(data) > length_limit: raise forms.ValidationError(ungettext( "Signature can't be longer than %(limit)s character.", "Signature can't be longer than %(limit)s characters.", length_limit) % {'limit': length_limit}) return data
class ReportPostForm(forms.Form): report_message = forms.CharField(label=_("Optional report message"), widget=forms.Textarea(attrs={'rows': 3}), required=False) def clean_report_message(self): data = self.cleaned_data['report_message'] if len(data) > 2000: raise forms.ValidationError("Report message cannot be " "longer than 2000 characters.") return data
class WarnUserForm(forms.Form): reason = forms.CharField(label=_("Warning Reason"), help_text=_("Optional message explaining why " "this warning was given."), widget=forms.Textarea(attrs={'rows': 8}), required=False) def clean_reason(self): data = self.cleaned_data['reason'] if len(data) > 2000: message = _("Warning reason can't be longer than 2000 characters.") raise forms.ValidationError(message) return data
class BanUsersForm(forms.Form): user_message = forms.CharField( label=_("User message"), required=False, max_length=1000, help_text=_("Optional message displayed to user " "instead of default one."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) staff_message = forms.CharField( label=_("Team message"), required=False, max_length=1000, help_text=_("Optional ban message for moderators and administrators."), widget=forms.Textarea(attrs={'rows': 3}), error_messages={ 'max_length': _("Message can't be longer than 1000 characters.") }) valid_until = forms.DateField( label=_("Expires after"), required=False, input_formats=['%m-%d-%Y'], widget=forms.DateInput(format='%m-%d-%Y', attrs={'data-date-format': 'MM-DD-YYYY'}), help_text=_('Leave this field empty for this ban to never expire.')) def clean_banned_value(self): data = self.cleaned_data['banned_value'] while '**' in data: data = data.replace('**', '*') if data == '*': raise forms.ValidationError(_("Banned value is too vague.")) return data
def UserIsActiveFormFactory(FormType, instance): is_active_fields = { 'is_active': forms.YesNoSwitch(label=EditUserForm.IS_ACTIVE_LABEL, help_text=EditUserForm.IS_ACTIVE_HELP_TEXT, initial=instance.is_active), 'is_active_staff_message': forms.CharField( label=EditUserForm.IS_ACTIVE_STAFF_MESSAGE_LABEL, help_text=EditUserForm.IS_ACTIVE_STAFF_MESSAGE_HELP_TEXT, initial=instance.is_active_staff_message, widget=forms.Textarea(attrs={'rows': 3}), required=False), } return type('UserIsActiveForm', (FormType, ), is_active_fields)
class EditUserForm(UserBaseForm): new_password = forms.CharField(label=_("Change password to"), widget=forms.PasswordInput, required=False) is_avatar_locked = forms.YesNoSwitch( label=_("Lock avatar"), help_text=_("Setting this to yes will stop user from " "changing his/her avatar, and will reset " "his/her avatar to procedurally generated one.")) avatar_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message for user explaining " "why he/she is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) avatar_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message for forum team members explaining " "why user is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature = forms.CharField(label=_("Signature contents"), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_signature_locked = forms.YesNoSwitch( label=_("Lock signature"), help_text=_("Setting this to yes will stop user from " "making changes to his/her signature.")) signature_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message to user explaining " "why his/hers signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message to team members explaining " "why user signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_hiding_presence = forms.YesNoSwitch(label=_("Hides presence")) limits_private_thread_invites_to = forms.TypedChoiceField( label=_("Who can add user to private threads"), coerce=int, choices=PRIVATE_THREAD_INVITES_LIMITS_CHOICES) subscribe_to_started_threads = forms.TypedChoiceField( label=_("Started threads"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES) subscribe_to_replied_threads = forms.TypedChoiceField( label=_("Replid threads"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES) class Meta: model = get_user_model() fields = [ 'username', 'email', 'title', 'is_avatar_locked', 'avatar_lock_user_message', 'avatar_lock_staff_message', 'signature', 'is_signature_locked', 'is_hiding_presence', 'limits_private_thread_invites_to', 'signature_lock_user_message', 'signature_lock_staff_message', 'subscribe_to_started_threads', 'subscribe_to_replied_threads' ] def clean_signature(self): data = self.cleaned_data['signature'] length_limit = settings.signature_length_max if len(data) > length_limit: raise forms.ValidationError( ungettext( "Signature can't be longer than %(limit)s character.", "Signature can't be longer than %(limit)s characters.", length_limit) % {'limit': length_limit}) return data
class EditUserForm(UserBaseForm): new_password = forms.CharField(label=_("Change password to"), widget=forms.PasswordInput, required=False) is_avatar_locked = forms.YesNoSwitch( label=_("Lock avatar"), help_text=_("Setting this to yes will stop user from " "changing his/her avatar, and will reset " "his/her avatar to procedurally generated one.")) avatar_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message for user explaining " "why he/she is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) avatar_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message for forum team members explaining " "why user is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature = forms.CharField(label=_("Signature contents"), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_signature_locked = forms.YesNoSwitch( label=_("Lock signature"), help_text=_("Setting this to yes will stop user from " "making changes to his/her signature.")) signature_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message to user explaining " "why his/hers signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message to team members explaining " "why user signature is locked."), widget=forms.Textarea(attrs={'rows': 3}), required=False) class Meta: model = get_user_model() fields = [ 'username', 'email', 'title', 'is_avatar_locked', 'avatar_lock_user_message', 'avatar_lock_staff_message', 'signature', 'is_signature_locked', 'signature_lock_user_message', 'signature_lock_staff_message' ] def clean_signature(self): data = self.cleaned_data['signature'] length_limit = settings.signature_length_max if len(data) > length_limit: raise forms.ValidationError( ungettext( "Signature can't be longer than %(limit)s character.", "Signature can't be longer than %(limit)s characters.", length_limit) % {'limit': length_limit}) return data
class RankForm(forms.ModelForm): name = forms.CharField( label=_("Name"), validators=[validate_sluggable()], help_text=_('Short and descriptive name of all users with this rank. ' '"The Team" or "Game Masters" are good examples.') ) title = forms.CharField( label=_("User title"), required=False, help_text=_('Optional, singular version of rank name displayed by ' 'user names. For example "GM" or "Dev".') ) description = forms.CharField( label=_("Description"), max_length=2048, required=False, widget=forms.Textarea(attrs={'rows': 3}), help_text=_("Optional description explaining function or status of " "members distincted with this rank.") ) roles = forms.ModelMultipleChoiceField( label=_("User roles"), widget=forms.CheckboxSelectMultiple, queryset=Role.objects.order_by('name'), required=False, help_text=_('Rank can give additional roles to users with it.') ) css_class = forms.CharField( label=_("CSS class"), required=False, help_text=_("Optional css class added to content belonging to this " "rank owner.") ) is_tab = forms.BooleanField( label=_("Give rank dedicated tab on users list"), required=False, help_text=_("Selecting this option will make users with this rank " "easily discoverable by others trough dedicated page on " "forum users list.") ) class Meta: model = Rank fields = [ 'name', 'description', 'css_class', 'title', 'roles', 'is_tab', ] def clean_name(self): data = self.cleaned_data['name'] self.instance.set_name(data) unique_qs = Rank.objects.filter(slug=self.instance.slug) if self.instance.pk: unique_qs = unique_qs.exclude(pk=self.instance.pk) if unique_qs.exists(): raise forms.ValidationError( _("This name collides with other rank.")) return data
class EditUserForm(UserBaseForm): IS_STAFF_LABEL = _("Is administrator") IS_STAFF_HELP_TEXT = _( "Designates whether the user can log into admin sites. " "If Django admin site is enabled, this user will need " "additional permissions assigned within it to admin " "Django modules.") IS_SUPERUSER_LABEL = _("Is superuser") IS_SUPERUSER_HELP_TEXT = _("Only administrators can access admin sites. " "In addition to admin site access, superadmins " "can also change other members admin levels.") IS_ACTIVE_LABEL = _('Is active') IS_ACTIVE_HELP_TEXT = _( "Designates whether this user should be treated as active. " "Turning this off is non-destructible way to remove user accounts.") IS_ACTIVE_STAFF_MESSAGE_LABEL = _("Staff message") IS_ACTIVE_STAFF_MESSAGE_HELP_TEXT = _( "Optional message for forum team members explaining " "why user's account has been disabled.") new_password = forms.CharField(label=_("Change password to"), widget=forms.PasswordInput, required=False) is_avatar_locked = forms.YesNoSwitch( label=_("Lock avatar"), help_text=_("Setting this to yes will stop user from changing " "his/her avatar, and will reset his/her avatar to " "procedurally generated one.")) avatar_lock_user_message = forms.CharField( label=_("User message"), help_text=_("Optional message for user explaining " "why he/she is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) avatar_lock_staff_message = forms.CharField( label=_("Staff message"), help_text=_("Optional message for forum team members explaining " "why user is banned form changing avatar."), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature = forms.CharField(label=_("Signature contents"), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_signature_locked = forms.YesNoSwitch( label=_("Lock signature"), help_text=_("Setting this to yes will stop user from " "making changes to his/her signature.")) signature_lock_user_message = forms.CharField( label=_("User message"), help_text= _("Optional message to user explaining why his/hers signature is locked." ), widget=forms.Textarea(attrs={'rows': 3}), required=False) signature_lock_staff_message = forms.CharField( label=_("Staff message"), help_text= _("Optional message to team members explaining why user signature is locked." ), widget=forms.Textarea(attrs={'rows': 3}), required=False) is_hiding_presence = forms.YesNoSwitch(label=_("Hides presence")) limits_private_thread_invites_to = forms.TypedChoiceField( label=_("Who can add user to private threads"), coerce=int, choices=PRIVATE_THREAD_INVITES_LIMITS_CHOICES) subscribe_to_started_threads = forms.TypedChoiceField( label=_("Started threads"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES) subscribe_to_replied_threads = forms.TypedChoiceField( label=_("Replid threads"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES) class Meta: model = get_user_model() fields = [ 'username', 'email', 'title', 'is_avatar_locked', 'avatar_lock_user_message', 'avatar_lock_staff_message', 'signature', 'is_signature_locked', 'is_hiding_presence', 'limits_private_thread_invites_to', 'signature_lock_user_message', 'signature_lock_staff_message', 'subscribe_to_started_threads', 'subscribe_to_replied_threads', ] def clean_signature(self): data = self.cleaned_data['signature'] length_limit = settings.signature_length_max if len(data) > length_limit: raise forms.ValidationError( ungettext( "Signature can't be longer than %(limit)s character.", "Signature can't be longer than %(limit)s characters.", length_limit) % {'limit': length_limit}) return data