Пример #1
0
class PermissionsForm(forms.Form):
    legend = _("Private threads")

    can_use_private_threads = YesNoSwitch(label=_("Can use private threads"))
    can_start_private_threads = YesNoSwitch(
        label=_("Can start private threads"))
    max_private_thread_participants = forms.IntegerField(
        label=_("Max number of users invited to private thread"),
        help_text=_("Enter 0 to don't limit number of participants."),
        initial=3,
        min_value=0,
    )
    can_add_everyone_to_private_threads = YesNoSwitch(
        label=_("Can add everyone to threads"),
        help_text=_(
            "Allows user to add users that are blocking him to private threads."
        ),
    )
    can_report_private_threads = YesNoSwitch(
        label=_("Can report private threads"),
        help_text=_("Allows user to report private threads they are "
                    "participating in, making them accessible to moderators."),
    )
    can_moderate_private_threads = YesNoSwitch(
        label=_("Can moderate private threads"),
        help_text=_("Allows user to read, reply, edit and delete content "
                    "in reported private threads."),
    )
Пример #2
0
class RolePermissionsForm(forms.Form):
    legend = _("Threads")

    can_see_unapproved_content_lists = YesNoSwitch(
        label=_("Can see unapproved content list"),
        help_text=_('Allows access to "unapproved" tab on threads lists for '
                    "easy listing of threads that are unapproved or contain "
                    "unapproved posts. Despite the tab being available on all "
                    "threads lists, it will only display threads belonging to "
                    "categories in which the user has permission to approve "
                    "content."),
    )
    can_see_reported_content_lists = YesNoSwitch(
        label=_("Can see reported content list"),
        help_text=_('Allows access to "reported" tab on threads lists for '
                    "easy listing of threads that contain reported posts. "
                    "Despite the tab being available on all categories "
                    "threads lists, it will only display threads belonging to "
                    "categories in which the user has permission to see posts "
                    "reports."),
    )
    can_omit_flood_protection = YesNoSwitch(
        label=_("Can omit flood protection"),
        help_text=_(
            "Allows posting more frequently than flood protection would."),
    )
Пример #3
0
class PermissionsForm(LimitedPermissionsForm):
    can_browse_users_list = CAN_BROWSE_USERS_LIST
    can_search_users = CAN_SEARCH_USERS
    can_follow_users = YesNoSwitch(label=_("Can follow other users"),
                                   initial=1)
    can_be_blocked = YesNoSwitch(label=_("Can be blocked by other users"),
                                 initial=0)
    can_see_users_name_history = CAN_SEE_USER_NAME_HISTORY
    can_see_ban_details = CAN_SEE_DETAILS
    can_see_users_emails = YesNoSwitch(label=_("Can see members e-mails"))
    can_see_users_ips = YesNoSwitch(label=_("Can see members IPs"))
    can_see_hidden_users = YesNoSwitch(
        label=_("Can see members that hide their presence"))
Пример #4
0
def StaffFlagUserFormFactory(FormType, instance):
    staff_fields = {
        'is_staff':
        YesNoSwitch(label=EditUserForm.IS_STAFF_LABEL,
                    help_text=EditUserForm.IS_STAFF_HELP_TEXT,
                    initial=instance.is_staff),
        'is_superuser':
        YesNoSwitch(label=EditUserForm.IS_SUPERUSER_LABEL,
                    help_text=EditUserForm.IS_SUPERUSER_HELP_TEXT,
                    initial=instance.is_superuser),
    }

    return type('StaffUserForm', (FormType, ), staff_fields)
Пример #5
0
class PermissionsForm(forms.Form):
    legend = _("Attachments")

    max_attachment_size = forms.IntegerField(
        label=_("Max attached file size (in kb)"),
        help_text=_("Enter 0 to don't allow uploading end deleting attachments."),
        initial=500,
        min_value=0
    )

    can_download_other_users_attachments = YesNoSwitch(
        label=_("Can download other users attachments")
    )
    can_delete_other_users_attachments = YesNoSwitch(label=_("Can delete other users attachments"))
Пример #6
0
class SearchUsersFormBase(forms.Form):
    username = forms.CharField(label=_("Username starts with"), required=False)
    email = forms.CharField(label=_("E-mail starts with"), required=False)
    profilefields = forms.CharField(label=_("Profile fields contain"),
                                    required=False)
    inactive = YesNoSwitch(label=_("Inactive only"))
    disabled = YesNoSwitch(label=_("Disabled only"))
    is_staff = YesNoSwitch(label=_("Admins only"))
    is_deleting_account = YesNoSwitch(label=_("Deleting their accounts"))

    def filter_queryset(self, criteria, queryset):
        if criteria.get('username'):
            queryset = queryset.filter(
                slug__startswith=criteria.get('username').lower())

        if criteria.get('email'):
            queryset = queryset.filter(
                email__istartswith=criteria.get('email'))

        if criteria.get('rank'):
            queryset = queryset.filter(rank_id=criteria.get('rank'))

        if criteria.get('role'):
            queryset = queryset.filter(roles__id=criteria.get('role'))

        if criteria.get('inactive'):
            queryset = queryset.filter(requires_activation__gt=0)

        if criteria.get('disabled'):
            queryset = queryset.filter(is_active=False)

        if criteria.get('is_staff'):
            queryset = queryset.filter(is_staff=True)

        if criteria.get('is_deleting_account'):
            queryset = queryset.filter(is_deleting_account=True)

        if criteria.get('profilefields', '').strip():
            queryset = profilefields.search_users(
                criteria.get('profilefields').strip(), queryset)

        return queryset
Пример #7
0
class PermissionsForm(forms.Form):
    legend = _("Account settings")

    name_changes_allowed = forms.IntegerField(
        label=_("Allowed username changes number"), min_value=0, initial=1)
    name_changes_expire = forms.IntegerField(
        label=_("Don't count username changes older than"),
        help_text=_("Number of days since name change that makes "
                    "that change no longer count to limit. Enter "
                    "zero to make all changes count."),
        min_value=0,
        initial=0)
    can_have_signature = YesNoSwitch(label=_("Can have signature"))
    allow_signature_links = YesNoSwitch(label=_("Can put links in signature"))
    allow_signature_images = YesNoSwitch(
        label=_("Can put images in signature"))
    allow_signature_blocks = YesNoSwitch(
        label=_("Can use text blocks in signature"),
        help_text=_("Controls whether or not users can put quote, code, "
                    "spoiler blocks and horizontal lines in signatures."))
Пример #8
0
def UserIsActiveFormFactory(FormType, instance):
    is_active_fields = {
        'is_active':
        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)
Пример #9
0
class RolePermissionsForm(forms.Form):
    legend = _("Polls")

    can_start_polls = forms.TypedChoiceField(
        label=_("Can start polls"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Own threads")),
            (2, _("All threads")),
        ],
    )
    can_edit_polls = forms.TypedChoiceField(
        label=_("Can edit polls"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Own polls")),
            (2, _("All polls")),
        ],
    )
    can_delete_polls = forms.TypedChoiceField(
        label=_("Can delete polls"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Own polls")),
            (2, _("All polls")),
        ],
    )
    poll_edit_time = forms.IntegerField(
        label=_("Time limit for own polls edits, in minutes"),
        help_text=_("Enter 0 to don't limit time for editing own polls."),
        initial=0,
        min_value=0,
    )
    can_always_see_poll_voters = YesNoSwitch(
        label=_("Can always see polls voters"),
        help_text=
        _("Allows users to see who voted in poll even if poll votes are secret."
          ),
    )
class TestForm(forms.Form):
    text_field = forms.CharField(label="Hello!",
                                 max_length=255,
                                 help_text="I am a help text.")
    textarea_field = forms.CharField(label="Message",
                                     max_length=255,
                                     widget=forms.Textarea())
    select_field = forms.ChoiceField(label="Choice",
                                     choices=(("y", "Yes"), ("n", "No")))
    checkbox_select_field = forms.MultipleChoiceField(
        label="Color",
        choices=(("r", "Red"), ("g", "Green"), ("b", "Blue")),
        widget=forms.CheckboxSelectMultiple,
    )
    multiple_select_field = forms.MultipleChoiceField(
        label="Rank",
        choices=(("r", "Red"), ("g", "Green"), ("b", "Blue")),
    )
    yesno_field = YesNoSwitch(label="Switch")
Пример #11
0
class PermissionsForm(forms.Form):
    legend = _("Users moderation")

    can_rename_users = YesNoSwitch(label=_("Can rename users"))
    can_moderate_avatars = YesNoSwitch(label=_("Can moderate avatars"))
    can_moderate_signatures = YesNoSwitch(label=_("Can moderate signatures"))
    can_moderate_profile_details = YesNoSwitch(
        label=_("Can moderate profile details"))
    can_ban_users = YesNoSwitch(label=_("Can ban users"))
    max_ban_length = forms.IntegerField(
        label=_("Max length, in days, of imposed ban"),
        help_text=_("Enter zero to let moderators impose permanent bans."),
        min_value=0,
        initial=0,
    )
    can_lift_bans = YesNoSwitch(label=_("Can lift bans"))
    max_lifted_ban_length = forms.IntegerField(
        label=_("Max length, in days, of lifted ban"),
        help_text=_("Enter zero to let moderators lift permanent bans."),
        min_value=0,
        initial=0,
    )
Пример #12
0
class PermissionsForm(forms.Form):
    legend = _("Search")

    can_search = YesNoSwitch(label=_("Can search site"), initial=1)
Пример #13
0
from misago.admin.forms import YesNoSwitch

from .decorators import authenticated_only

__all__ = [
    'allow_browse_users_list',
    'can_browse_users_list',
    'allow_follow_user',
    'can_follow_user',
    'allow_block_user',
    'can_block_user',
    'allow_see_ban_details',
    'can_see_ban_details',
]

CAN_BROWSE_USERS_LIST = YesNoSwitch(label=_("Can browse users list"),
                                    initial=1)
CAN_SEARCH_USERS = YesNoSwitch(label=_("Can search user profiles"), initial=1)
CAN_SEE_USER_NAME_HISTORY = YesNoSwitch(
    label=_("Can see other members name history"))
CAN_SEE_DETAILS = YesNoSwitch(
    label=_("Can see members bans details"),
    help_text=_(
        "Allows users with this permission to see user and staff ban messages."
    ))


class LimitedPermissionsForm(forms.Form):
    legend = _("User profiles")

    can_browse_users_list = CAN_BROWSE_USERS_LIST
    can_search_users = CAN_SEARCH_USERS
Пример #14
0
class PermissionsForm(forms.Form):
    legend = _("Category access")

    can_see = YesNoSwitch(label=_("Can see category"))
    can_browse = YesNoSwitch(label=_("Can see category contents"))
Пример #15
0
class CategoryPermissionsForm(forms.Form):
    legend = _("Threads")

    can_see_all_threads = forms.TypedChoiceField(
        label=_("Can see threads"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("Started threads")),
            (1, _("All threads")),
        ],
    )

    can_start_threads = YesNoSwitch(label=_("Can start threads"))
    can_reply_threads = YesNoSwitch(label=_("Can reply to threads"))

    can_edit_threads = forms.TypedChoiceField(
        label=_("Can edit threads"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Own threads")),
            (2, _("All threads")),
        ],
    )
    can_hide_own_threads = forms.TypedChoiceField(
        label=_("Can hide own threads"),
        help_text=_("Only threads started within time limit and "
                    "with no replies can be hidden."),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Hide threads")),
            (2, _("Delete threads")),
        ],
    )
    thread_edit_time = forms.IntegerField(
        label=_("Time limit for own threads edits, in minutes"),
        help_text=_("Enter 0 to don't limit time for editing own threads."),
        initial=0,
        min_value=0,
    )
    can_hide_threads = forms.TypedChoiceField(
        label=_("Can hide all threads"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Hide threads")),
            (2, _("Delete threads")),
        ],
    )

    can_pin_threads = forms.TypedChoiceField(
        label=_("Can pin threads"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Locally")),
            (2, _("Globally")),
        ],
    )
    can_close_threads = YesNoSwitch(label=_("Can close threads"))
    can_move_threads = YesNoSwitch(label=_("Can move threads"))
    can_merge_threads = YesNoSwitch(label=_("Can merge threads"))

    can_edit_posts = forms.TypedChoiceField(
        label=_("Can edit posts"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Own posts")),
            (2, _("All posts")),
        ],
    )
    can_hide_own_posts = forms.TypedChoiceField(
        label=_("Can hide own posts"),
        help_text=
        _("Only last posts to thread made within edit time limit can be hidden."
          ),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Hide posts")),
            (2, _("Delete posts")),
        ],
    )
    post_edit_time = forms.IntegerField(
        label=_("Time limit for own post edits, in minutes"),
        help_text=_("Enter 0 to don't limit time for editing own posts."),
        initial=0,
        min_value=0,
    )
    can_hide_posts = forms.TypedChoiceField(
        label=_("Can hide all posts"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Hide posts")),
            (2, _("Delete posts")),
        ],
    )

    can_see_posts_likes = forms.TypedChoiceField(
        label=_("Can see posts likes"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Number only")),
            (2, _("Number and list of likers")),
        ],
    )
    can_like_posts = YesNoSwitch(
        label=_("Can like posts"),
        help_text=_(
            "Only users with this permission to see likes can like posts."),
    )

    can_protect_posts = YesNoSwitch(
        label=_("Can protect posts"),
        help_text=_(
            "Only users with this permission can edit protected posts."),
    )
    can_move_posts = YesNoSwitch(
        label=_("Can move posts"),
        help_text=_("Will be able to move posts to other threads."),
    )
    can_merge_posts = YesNoSwitch(label=_("Can merge posts"))
    can_approve_content = YesNoSwitch(
        label=_("Can approve content"),
        help_text=_("Will be able to see and approve unapproved content."),
    )
    can_report_content = YesNoSwitch(label=_("Can report posts"))
    can_see_reports = YesNoSwitch(label=_("Can see reports"))

    can_hide_events = forms.TypedChoiceField(
        label=_("Can hide events"),
        coerce=int,
        initial=0,
        choices=[
            (0, _("No")),
            (1, _("Hide events")),
            (2, _("Delete events")),
        ],
    )

    require_threads_approval = YesNoSwitch(label=_("Require threads approval"))
    require_replies_approval = YesNoSwitch(label=_("Require replies approval"))
    require_edits_approval = YesNoSwitch(label=_("Require edits approval"))
Пример #16
0
class CategoryFormBase(forms.ModelForm):
    name = forms.CharField(label=_("Name"), validators=[validate_sluggable()])
    description = forms.CharField(
        label=_("Description"),
        max_length=2048,
        required=False,
        widget=forms.Textarea(attrs={'rows': 3}),
        help_text=_(
            "Optional description explaining category intented purpose."),
    )
    css_class = forms.CharField(
        label=_("CSS class"),
        required=False,
        help_text=
        _("Optional CSS class used to customize this category appearance from templates."
          ),
    )
    is_closed = YesNoSwitch(
        label=_("Closed category"),
        required=False,
        help_text=_(
            "Only members with valid permissions can post in closed categories."
        ),
    )
    css_class = forms.CharField(
        label=_("CSS class"),
        required=False,
        help_text=
        _("Optional CSS class used to customize this category appearance from templates."
          ),
    )
    require_threads_approval = YesNoSwitch(
        label=_("Threads"),
        required=False,
        help_text=
        _("All threads started in this category will require moderator approval."
          ),
    )
    require_replies_approval = YesNoSwitch(
        label=_("Replies"),
        required=False,
        help_text=
        _("All replies posted in this category will require moderator approval."
          ),
    )
    require_edits_approval = YesNoSwitch(
        label=_("Edits"),
        required=False,
        help_text=
        _("Will make all edited replies return to unapproved state for moderator to review."
          ),
    )
    prune_started_after = forms.IntegerField(
        label=_("Thread age"),
        min_value=0,
        help_text=_(
            "Prune thread if number of days since its creation is greater than specified. "
            "Enter 0 to disable this pruning criteria."),
    )
    prune_replied_after = forms.IntegerField(
        label=_("Last reply"),
        min_value=0,
        help_text=_(
            "Prune thread if number of days since last reply is greater than specified. "
            "Enter 0 to disable this pruning criteria."),
    )

    class Meta:
        model = Category
        fields = [
            'name',
            'description',
            'css_class',
            'is_closed',
            'require_threads_approval',
            'require_replies_approval',
            'require_edits_approval',
            'prune_started_after',
            'prune_replied_after',
            'archive_pruned_in',
        ]

    def clean_copy_permissions(self):
        data = self.cleaned_data['copy_permissions']
        if data and data.pk == self.instance.pk:
            message = _(
                "Permissions cannot be copied from category into itself.")
            raise forms.ValidationError(message)
        return data

    def clean_archive_pruned_in(self):
        data = self.cleaned_data['archive_pruned_in']
        if data and data.pk == self.instance.pk:
            message = _("Category cannot act as archive for itself.")
            raise forms.ValidationError(message)
        return data

    def clean(self):
        data = super().clean()
        self.instance.set_name(data.get('name'))
        return data
Пример #17
0
class AnonymousPermissionsForm(forms.Form):
    legend = _("Attachments")

    can_download_other_users_attachments = YesNoSwitch(label=_("Can download attachments"))
Пример #18
0
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"),
        strip=False,
        widget=forms.PasswordInput,
        required=False,
    )

    is_avatar_locked = 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 = 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 = YesNoSwitch(label=_("Hides presence"))

    limits_private_thread_invites_to = forms.TypedChoiceField(
        label=_("Who can add user to private threads"),
        coerce=int,
        choices=UserModel.LIMIT_INVITES_TO_CHOICES)

    subscribe_to_started_threads = forms.TypedChoiceField(
        label=_("Started threads"),
        coerce=int,
        choices=UserModel.SUBSCRIBE_CHOICES)
    subscribe_to_replied_threads = forms.TypedChoiceField(
        label=_("Replid threads"),
        coerce=int,
        choices=UserModel.SUBSCRIBE_CHOICES)

    class Meta:
        model = UserModel
        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 __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request')

        super().__init__(*args, **kwargs)

        profilefields.add_fields_to_admin_form(self.request, self.instance,
                                               self)

    def get_profile_fields_groups(self):
        profile_fields_groups = []
        for group in self._profile_fields_groups:
            fields_group = {
                'name': group['name'],
                'fields': [],
            }

            for fieldname in group['fields']:
                fields_group['fields'].append(self[fieldname])

            profile_fields_groups.append(fields_group)
        return profile_fields_groups

    def clean_signature(self):
        data = self.cleaned_data['signature']

        length_limit = settings.signature_length_max
        if len(data) > length_limit:
            raise forms.ValidationError(
                ngettext(
                    "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

    def clean(self):
        data = super().clean()
        return profilefields.clean_form(self.request, self.instance, self,
                                        data)
Пример #19
0
class BanForm(forms.ModelForm):
    check_type = forms.TypedChoiceField(
        label=_("Check type"),
        coerce=int,
        choices=Ban.CHOICES,
    )
    registration_only = YesNoSwitch(
        label=_("Restrict this ban to registrations"),
        help_text=
        _("Changing this to yes will make this ban check be only performed on registration "
          "step. This is good if you want to block certain registrations like ones from "
          "recently comprimised e-mail providers, without harming existing users."
          ),
    )
    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 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 = IsoDateTimeField(
        label=_("Expires on"),
        required=False,
        help_text=_("Leave this field empty for this ban to never expire."))

    class Meta:
        model = Ban
        fields = [
            'check_type',
            'registration_only',
            'banned_value',
            'user_message',
            'staff_message',
            'expires_on',
        ]

    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
Пример #20
0
class YesNoForm(forms.Form):
    test_field = YesNoSwitch(label='Hello!')
Пример #21
0
def create_yesno(setting, kwargs, extra):
    return YesNoSwitch(**kwargs)