Exemple #1
0
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.'))
Exemple #2
0
def create_checkbox(setting, kwargs, extra):
    kwargs['widget'] = forms.CheckboxSelectMultiple()
    kwargs['choices'] = extra.get('choices', [])

    if extra.get('min') or extra.get('max'):
        kwargs['validators'] = [
            ValidateChoicesNum(extra.pop('min', 0), extra.pop('max', 0))
        ]

    if setting.python_type == 'int':
        return forms.TypedMultipleChoiceField(coerce='int', **kwargs)
    else:
        return forms.MultipleChoiceField(**kwargs)