Esempio n. 1
0
    def finalize_form(self):
        self.layout = [
            [
                None,
                [
                    ('thread_name', {
                        'label': _("New Thread Name")
                    }),
                    ('thread_forum', {
                        'label': _("New Thread Forum")
                    }),
                ],
            ],
        ]

        self.fields['thread_name'] = forms.CharField(
            max_length=self.request.settings['thread_name_max'],
            validators=[
                validate_sluggable(
                    _("Thread name must contain at least one alpha-numeric character."
                      ), _("Thread name is too long. Try shorter name."))
            ])
        self.fields['thread_forum'] = ForumChoiceField(
            queryset=Forum.objects.get(
                special='root').get_descendants().filter(
                    pk__in=self.request.acl.forums.acl['can_browse']))
Esempio n. 2
0
class WarnLevelForm(Form):
    name = forms.CharField(label=_("Warning Level Name"),
                           max_length=255, validators=[validate_sluggable(
                                                                          _("Warning level name must contain alphanumeric characters."),
                                                                          _("Warning level name is too long.")
                                                                          )])
    description = forms.CharField(label=_("Warning Level Description"),
                                  help_text=_("Optional message displayed to members with this warning level."),
                                  widget=forms.Textarea, required=False)
    expires_after_minutes = forms.IntegerField(label=_("Warning Level Expiration"),
                                               help_text=_("Enter number of minutes since this warning level was imposed on member until it's reduced and lower level is imposed, or 0 to make this warning level permanent."),
                                               initial=0, min_value=0)
    restrict_posting_replies = forms.TypedChoiceField(
        label=_("Restrict Replies Posting"),
        choices=(
           (WarnLevel.RESTRICT_NO, _("No restrictions")),
           (WarnLevel.RESTRICT_MODERATOR_REVIEW, _("Review by moderator")),
           (WarnLevel.RESTRICT_DISALLOW, _("Disallowed")),
        ),
        coerce=int, initial=0)
    restrict_posting_threads = forms.TypedChoiceField(
        label=_("Restrict Threads Posting"),
        choices=(
           (WarnLevel.RESTRICT_NO, _("No restrictions")),
           (WarnLevel.RESTRICT_MODERATOR_REVIEW, _("Review by moderator")),
           (WarnLevel.RESTRICT_DISALLOW, _("Disallowed")),
        ),
        coerce=int, initial=0)
Esempio n. 3
0
    def finalize_form(self):
        self.fields['new_forum'] = ForumChoiceField(queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']), initial=self.threads[0].forum)
        self.fields['thread_name'] = forms.CharField(
                                                     max_length=self.request.settings['thread_name_max'],
                                                     initial=self.threads[0].name,
                                                     validators=[validate_sluggable(
                                                                                    _("Thread name must contain at least one alpha-numeric character."),
                                                                                    _("Thread name is too long. Try shorter name.")
                                                                                    )])
        self.layout = [
                       [
                        None,
                        [
                         ('thread_name', {'label': _("Thread Name"), 'help_text': _("Name of new thread that will be created as result of merge.")}),
                         ('new_forum', {'label': _("Thread Forum"), 'help_text': _("Select forum you want to put new thread in.")}),
                         ],
                        ],
                       [
                        _("Merge Order"),
                        [
                         ],
                        ],
                       ]

        choices = []
        for i, thread in enumerate(self.threads):
            choices.append((str(i), i + 1))
        for i, thread in enumerate(self.threads):
            self.fields['thread_%s' % thread.pk] = forms.ChoiceField(choices=choices, initial=str(i))
            self.layout[1][1].append(('thread_%s' % thread.pk, {'label': thread.name}))
Esempio n. 4
0
    def finalize_form(self):
        self.fields['new_forum'] = ForumChoiceField(
            queryset=Forum.objects.get(
                special='root').get_descendants().filter(
                    pk__in=self.request.acl.forums.acl['can_browse']),
            initial=self.threads[0].forum)
        self.fields['thread_name'] = forms.CharField(
            max_length=self.request.settings['thread_name_max'],
            initial=self.threads[-1].name,
            validators=[
                validate_sluggable(
                    _("Thread name must contain at least one alpha-numeric character."
                      ), _("Thread name is too long. Try shorter name."))
            ])

        self.layout = [
            [
                None,
                [
                    ('thread_name', {
                        'label':
                        _("Thread Name"),
                        'help_text':
                        _("Name of new thread that will be created as result of merge."
                          )
                    }),
                    ('new_forum', {
                        'label':
                        _("Thread Forum"),
                        'help_text':
                        _("Select forum you want to put new thread in.")
                    }),
                ],
            ],
        ]
Esempio n. 5
0
    def finalize_form(self):
        choices = [(0, _("Don't use any polls"))]
        for thread in self.threads:
            if thread.has_poll:
                choices.append((thread.pk, thread.name))

        if len(choices) > 2:
            self.add_field('final_poll', forms.TypedChoiceField(label=_("Final Poll"),
                                                                help_text=_("More than one of threads that you are going to merge has poll. Select poll that will be used in merged thread or delete all polls."),
                                                                choices=choices,
                                                                coerce=int,
                                                                initial=choices[1][0]))

        self.add_field('new_forum', ForumChoiceField(label=_("Thread Forum"),
                                                      help_text=_("Select forum you want to put new thread in."),
                                                      queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']),
                                                      initial=self.threads[0].forum))
        self.add_field('thread_name', forms.CharField(label=_("Thread Name"),
                                                      help_text=_("Name of new thread that will be created as result of merge."),
                                                      max_length=settings.thread_name_max,
                                                      initial=self.threads[-1].name,
                                                      validators=[validate_sluggable(
                                                                                     _("Thread name must contain at least one alpha-numeric character."),
                                                                                     _("Thread name is too long. Try shorter name.")
                                                                                     )]))
Esempio n. 6
0
 def finalize_form(self):
     self.fields['thread_name'] = forms.CharField(label=_("New Thread Name"),
                                                  max_length=settings.thread_name_max,
                                                  validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
                                                                                 _("Thread name is too long. Try shorter name.")
                                                                                 )])
     self.fields['thread_forum'] = ForumChoiceField(label=_("New Thread Forum"),
                                                    queryset=Forum.objects.get(special='root').get_descendants().filter(pk__in=self.request.acl.forums.acl['can_browse']))
Esempio n. 7
0
 def finalize_form(self):
     super(NewThreadForm, self).finalize_form()
     self.layout[0][1].append(('thread_name', {'label': _("Thread Name")}))
     self.fields['thread_name'] = forms.CharField(
         max_length=self.request.settings['thread_name_max'],
         validators=[
             validate_sluggable(
                 _("Thread name must contain at least one alpha-numeric character."
                   ), _("Thread name is too long. Try shorter name."))
         ])
Esempio n. 8
0
class ForumRoleForm(Form):
    name = forms.CharField(
        label=_("Role Name"),
        help_text=_(
            "Role Name is used to identify this role in Admin Control Panel."),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Role name must contain alphanumeric characters."),
                _("Role name is too long."))
        ])
Esempio n. 9
0
File: forms.py Progetto: xyzz/Misago
class PolicyForm(Form):
    name = forms.CharField(
        max_length=255,
        validators=[
            validate_sluggable(
                _("Policy name must contain alphanumeric characters."),
                _("Policy name is too long."))
        ])
    email = forms.CharField(max_length=255, required=False)
    posts = forms.IntegerField(min_value=0, initial=0)
    registered = forms.IntegerField(min_value=0, initial=0)
    last_visit = forms.IntegerField(min_value=0, initial=0)

    layout = (
        (_("Basic Policy Options"), (('name', {
            'label':
            _("Policy Name"),
            'help_text':
            _("Short, descriptive name of this pruning policy.")
        }), )),
        (_("Pruning Policy Criteria"), (
            ('email', {
                'label':
                _("Member E-mail Address ends with"),
                'help_text':
                _("If you want to, you can enter more than one e-mail suffix by separating them with comma."
                  )
            }),
            ('posts', {
                'label':
                _("Member has no more posts than"),
                'help_text':
                _("Maximum number of posts member is allowed to have to fall under policy. For example if you enter in 10 posts and make this only criteria, every user that has less than 10 posts will be deleted. Enter zero to dont use this criteria"
                  )
            }),
            ('registered', {
                'label':
                _("User is member for no more than"),
                'help_text':
                _("Maximal number of days user is member for. For exmaple if you enter in 15 days and make this only criteria, every user who is member for less than 15 days will be deleted. Enter zero to dont use this criteria."
                  )
            }),
            ('last_visit', {
                'label':
                _("User last visit was before"),
                'help_text':
                _("Maximal allowed inactivity period in days. For example if you enter in 300 days and make this only criteria for deleting users, every member who did not signed into forums in last 300 days will be deleted. Enter zero to dont use this criteria."
                  )
            }),
        )),
    )
Esempio n. 10
0
class AttachmentTypeForm(Form):
    name = forms.CharField(
        label=_("Type Name"),
        max_length=256,
        validators=[
            validate_sluggable(_("Name must contain alphanumeric characters."),
                               _("Type name is too long."))
        ])
    extensions = forms.CharField(
        label=_("File Extensions"),
        help_text=
        _("Enter file name extensions used by this attachment type. Don't enter dots. If this attachment type supports more than one extension, separate them with coma, for example: jpg,jpeg."
          ),
        max_length=255)
    size_limit = forms.IntegerField(
        label=_("Hard File Size Limit"),
        help_text=
        _("In addition to role-based single uploaded file size limit you can set additional limit for all future attachments of this type. To set limit, enter number of kilobytes, otherwhise enter 0. If limit is defined, forum will use lower limit (this one or role one) during validation of uploaded file, unless uploader has no single uploaded file size limit, which is when uploaded file size validation is not performed."
          ),
        min_value=0,
        initial=0)
    roles = forms.ModelMultipleChoiceField(
        label=_("Restrict to certain roles"),
        required=None,
        help_text=
        _("You can restrict uploading files of this type to users with certain roles by selecting them in above list."
          ),
        queryset=Role.objects.order_by('name'),
        widget=forms.CheckboxSelectMultiple)

    def clean_extension(self, extension):
        extension = extension.strip().lower()
        try:
            while extension[0] == '.':
                extension = extension[1:]
        except IndexError:
            return None
        return extension

    def clean_extensions(self):
        clean_data = []
        data = self.cleaned_data['extensions'].strip().lower()
        for extension in data.split(','):
            extension = self.clean_extension(extension)
            if extension and not extension in clean_data:
                clean_data.append(extension)
        if not clean_data:
            raise forms.ValidationError(
                _("You have to specify at least one file extension."))
        return ','.join(clean_data)
Esempio n. 11
0
class PrefixFormBase(Form):
    name = forms.CharField(
        label=_("Prefix Name"),
        max_length=16,
        validators=[
            validate_sluggable(
                _("Prefix must contain alphanumeric characters."),
                _("Prefix name is too long."))
        ])
    style = forms.CharField(
        label=_("Prefix CSS Class"),
        help_text=_(
            "CSS class that will be used to style this thread prefix."),
        max_length=255,
        required=False)
Esempio n. 12
0
class NewsletterForm(Form):
    name = forms.CharField(
        label=_("Newsletter Name"),
        help_text=
        _("Newsletter name will be used as message subject in e-mails sent to members."
          ),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Newsletter name must contain alphanumeric characters."),
                _("Newsletter name is too long."))
        ])
    step_size = forms.IntegerField(
        label=_("Step Size"),
        help_text=
        _("Number of users that message will be sent to before forum refreshes page displaying sending progress."
          ),
        initial=300,
        min_value=1)
    content_html = forms.CharField(
        label=_("HTML Message"),
        help_text=_(
            "HTML message visible to members who can read HTML e-mails."),
        widget=forms.Textarea)
    content_plain = forms.CharField(
        label=_("Plain Text Message"),
        help_text=
        _("Alternative plain text message that will be visible to members that can't or dont want to read HTML e-mails."
          ),
        widget=forms.Textarea)
    ignore_subscriptions = forms.BooleanField(
        label=_("Ignore members preferences"),
        help_text=
        _("Change this option to yes if you want to send this newsletter to members that don't want to receive newsletters. This is good for emergencies."
          ),
        widget=YesNoSwitch,
        required=False)
    ranks = forms.ModelMultipleChoiceField(
        label=_("Limit to roles"),
        help_text=
        _("You can limit this newsletter only to members who have specific ranks. If you dont set any ranks, this newsletter will be sent to every user."
          ),
        widget=forms.CheckboxSelectMultiple,
        queryset=Rank.objects.order_by('name').all(),
        required=False)
Esempio n. 13
0
class ForumRoleForm(Form):
    name = forms.CharField(
        max_length=255,
        validators=[
            validate_sluggable(
                _("Role name must contain alphanumeric characters."),
                _("Role name is too long."))
        ])

    def finalize_form(self):
        self.layout = ((
            _("Basic Role Options"),
            (('name', {
                'label':
                _("Role Name"),
                'help_text':
                _("Role Name is used to identify this role in Admin Control Panel."
                  )
            }), ),
        ), )
Esempio n. 14
0
    def finalize_form(self):
        choices = [(0, _("Don't use any polls"))]
        for thread in self.threads:
            if thread.has_poll:
                choices.append((thread.pk, thread.name))

        if len(choices) > 2:
            self.add_field(
                'final_poll',
                forms.TypedChoiceField(
                    label=_("Final Poll"),
                    help_text=
                    _("More than one of threads that you are going to merge has poll. Select poll that will be used in merged thread or delete all polls."
                      ),
                    choices=choices,
                    coerce=int,
                    initial=choices[1][0]))

        self.add_field(
            'new_forum',
            ForumChoiceField(
                label=_("Thread Forum"),
                help_text=_("Select forum you want to put new thread in."),
                queryset=Forum.objects.get(
                    special='root').get_descendants().filter(
                        pk__in=self.request.acl.forums.acl['can_browse']),
                initial=self.threads[0].forum))
        self.add_field(
            'thread_name',
            forms.CharField(
                label=_("Thread Name"),
                help_text=
                _("Name of new thread that will be created as result of merge."
                  ),
                max_length=settings.thread_name_max,
                initial=self.threads[-1].name,
                validators=[
                    validate_sluggable(
                        _("Thread name must contain at least one alpha-numeric character."
                          ), _("Thread name is too long. Try shorter name."))
                ]))
Esempio n. 15
0
class RoleForm(Form):
    name = forms.CharField(
        label=_("Role Name"),
        help_text=_(
            "Role Name is used to identify this role in Admin Control Panel."),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Role name must contain alphanumeric characters."),
                _("Role name is too long."))
        ])
    protected = forms.BooleanField(
        label=_("Protect this Role"),
        help_text=_(
            "Only system administrators can edit or assign protected roles."),
        widget=YesNoSwitch,
        required=False)

    def finalize_form(self):
        if not self.request.user.is_god():
            del self.fields['protected']
Esempio n. 16
0
class RedirectForm(Form, CleanAttrsMixin):
    parent = False
    perms = False
    name = forms.CharField(
        max_length=255,
        validators=[
            validate_sluggable(
                _("Redirect name must contain alphanumeric characters."),
                _("Redirect name is too long."))
        ])
    description = forms.CharField(widget=forms.Textarea, required=False)
    redirect = forms.URLField(max_length=255)
    style = forms.CharField(max_length=255, required=False)

    layout = (
        (
            _("Basic Options"),
            (
                ('parent', {
                    'label': _("Redirect Parent")
                }),
                ('perms', {
                    'label': _("Copy Permissions from")
                }),
                ('name', {
                    'label': _("Redirect Name")
                }),
                ('redirect', {
                    'label': _("Redirect URL")
                }),
                ('description', {
                    'label': _("Redirect Description")
                }),
            ),
        ),
        (
            _("Display Options"),
            (
                ('attrs', {
                    'label':
                    _("Forum Attributes"),
                    'help_text':
                    _('Custom templates can check forums for predefined attributes that will change way subforums lists are rendered.'
                      )
                }),
                ('style', {
                    'label':
                    _("Redirect Style"),
                    'help_text':
                    _('You can add custom CSS classess to this redirect to change way it looks on forums lists.'
                      )
                }),
            ),
        ),
    )

    def finalize_form(self):
        self.add_field(
            'perms',
            TreeNodeChoiceField(
                label=_("Copy Permissions from"),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(),
                level_indicator=u'- - ',
                required=False,
                empty_label=_("Don't copy permissions")))
Esempio n. 17
0
class ForumForm(Form, CleanAttrsMixin):
    parent = False
    perms = False
    pruned_archive = False
    name = forms.CharField(
        label=_("Forum Name"),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Forum name must contain alphanumeric characters."),
                _("Forum name is too long."))
        ])
    description = forms.CharField(label=_("Forum Description"),
                                  widget=forms.Textarea,
                                  required=False)
    closed = forms.BooleanField(label=_("Closed Forum"),
                                widget=YesNoSwitch,
                                required=False)
    style = forms.CharField(
        label=_("Forum Style"),
        help_text=
        _('You can add custom CSS classess to this forum to change way it looks on forums lists.'
          ),
        max_length=255,
        required=False)
    prune_start = forms.IntegerField(
        label=_("Delete threads with first post older than"),
        help_text=
        _('Enter number of days since thread start after which thread will be deleted or zero to don\'t delete threads.'
          ),
        min_value=0,
        initial=0)
    prune_last = forms.IntegerField(
        label=_("Delete threads with last post older than"),
        help_text=
        _('Enter number of days since since last reply in thread after which thread will be deleted or zero to don\'t delete threads.'
          ),
        min_value=0,
        initial=0)
    attrs = forms.CharField(
        label=_("Forum Attributes"),
        help_text=
        _('Custom templates can check forums for predefined attributes that will change way subforums lists are rendered.'
          ),
        max_length=255,
        required=False)
    show_details = forms.BooleanField(
        label=_("Show Subforums Details"),
        help_text=
        _("Allows you to prevent this forum's subforums from displaying statistics, last post data, etc. ect. on subforums list."
          ),
        widget=YesNoSwitch,
        required=False,
        initial=True)

    layout = (
        (
            _("Basic Options"),
            (
                ('parent', {
                    'label': _("Forum Parent")
                }),
                ('perms', {
                    'label': _("Copy Permissions from")
                }),
                ('name', {
                    'label': _("Forum Name")
                }),
                ('description', {
                    'label': _("Forum Description")
                }),
                ('closed', {
                    'label': _("Closed Forum")
                }),
            ),
        ),
        (
            _("Prune Forum"),
            (('prune_start', {
                'label':
                _("Delete threads with first post older than"),
                'help_text':
                _('Enter number of days since thread start after which thread will be deleted or zero to don\'t delete threads.'
                  )
            }), ('prune_last', {
                'label':
                _("Delete threads with last post older than"),
                'help_text':
                _('Enter number of days since since last reply in thread after which thread will be deleted or zero to don\'t delete threads.'
                  )
            }), ('pruned_archive', {
                'label':
                _("Archive pruned threads?"),
                'help_text':
                _('If you want, you can archive pruned threads in other forum instead of deleting them.'
                  )
            })),
        ),
        (
            _("Display Options"),
            (
                ('attrs', {
                    'label':
                    _("Forum Attributes"),
                    'help_text':
                    _('Custom templates can check forums for predefined attributes that will change way subforums lists are rendered.'
                      )
                }),
                ('show_details', {
                    'label':
                    _("Show Subforums Details"),
                    'help_text':
                    _("Allows you to prevent this forum's subforums from displaying statistics, last post data, etc. ect. on subforums list."
                      )
                }),
                ('style', {
                    'label':
                    _("Forum Style"),
                    'help_text':
                    _('You can add custom CSS classess to this forum to change way it looks on forums lists.'
                      )
                }),
            ),
        ),
    )

    def finalize_form(self):
        self.add_field(
            'perms',
            TreeNodeChoiceField(
                label=_("Copy Permissions from"),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(),
                level_indicator=u'- - ',
                required=False,
                empty_label=_("Don't copy permissions")))
        self.add_field(
            'pruned_archive',
            TreeNodeChoiceField(
                label=_("Archive pruned threads?"),
                help_text=
                _('If you want, you can archive pruned threads in other forum instead of deleting them.'
                  ),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(),
                level_indicator=u'- - ',
                required=False,
                empty_label=_("Don't archive pruned threads")))

    def clean_pruned_archive(self):
        data = self.cleaned_data['pruned_archive']
        if data and data.pk == self.target_forum.pk:
            raise forms.ValidationError(_("Forum cannot be its own archive."))
        return data
Esempio n. 18
0
class NewNodeForm(Form, CleanAttrsMixin):
    parent = False
    perms = False
    role = forms.ChoiceField(
        label=_("Node Type"),
        help_text=
        _("Each Node has specific role in forums tree. This role cannot be changed after node is created."
          ),
        choices=(
            ('category', _("Category")),
            ('forum', _("Forum")),
            ('redirect', _("Redirection")),
        ))
    name = forms.CharField(
        label=_("Node Name"),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Category name must contain alphanumeric characters."),
                _("Category name is too long."))
        ])
    redirect = forms.URLField(
        label=_("Redirect URL"),
        help_text=
        _("Redirection nodes require you to specify URL they will redirect users to upon click."
          ),
        max_length=255,
        required=False)
    description = forms.CharField(label=_("Node Description"),
                                  widget=forms.Textarea,
                                  required=False)
    closed = forms.BooleanField(label=_("Closed Node"),
                                widget=YesNoSwitch,
                                required=False)
    attrs = forms.CharField(
        label=_("Node Style"),
        help_text=
        _('You can add custom CSS classess to this node, to change way it looks on board index.'
          ),
        max_length=255,
        required=False)
    show_details = forms.BooleanField(
        label=_("Node Style"),
        help_text=
        _('You can add custom CSS classess to this node, to change way it looks on board index.'
          ),
        widget=YesNoSwitch,
        required=False,
        initial=True)
    style = forms.CharField(
        label=_("Node Style"),
        help_text=
        _('You can add custom CSS classess to this node, to change way it looks on board index.'
          ),
        max_length=255,
        required=False)

    layout = (
        (
            _("Basic Options"),
            (
                ('parent', {
                    'label': _("Node Parent")
                }),
                ('perms', {
                    'label': _("Copy Permissions from")
                }),
                ('role', {
                    'label':
                    _("Node Type"),
                    'help_text':
                    _("Each Node has specific role in forums tree. This role cannot be changed after node is created."
                      )
                }),
                ('name', {
                    'label': _("Node Name")
                }),
                ('description', {
                    'label': _("Node Description")
                }),
                ('redirect', {
                    'label':
                    _("Redirect URL"),
                    'help_text':
                    _("Redirection nodes require you to specify URL they will redirect users to upon click."
                      )
                }),
                ('closed', {
                    'label': _("Closed Node")
                }),
            ),
        ),
        (
            _("Display Options"),
            (
                ('attrs', {
                    'label':
                    _("Node Attributes"),
                    'help_text':
                    _('Custom templates can check nodes for predefined attributes that will change way they are rendered.'
                      )
                }),
                ('show_details', {
                    'label':
                    _("Show Subforums Details"),
                    'help_text':
                    _('Allows you to prevent this node subforums from displaying statistics, last post data, etc. ect. on forums lists.'
                      )
                }),
                ('style', {
                    'label':
                    _("Node Style"),
                    'help_text':
                    _('You can add custom CSS classess to this node, to change way it looks on board index.'
                      )
                }),
            ),
        ),
    )

    def finalize_form(self):
        self.add_field(
            'parent',
            TreeNodeChoiceField(
                label=_("Node Parent"),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(
                    include_self=True),
                level_indicator=u'- - '))
        self.add_field(
            'perms',
            TreeNodeChoiceField(
                label=_("Copy Permissions from"),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(),
                level_indicator=u'- - ',
                required=False,
                empty_label=_("Don't copy permissions")))

    def clean(self):
        cleaned_data = super(NewNodeForm, self).clean()
        node_role = cleaned_data['role']

        if node_role != 'category' and cleaned_data['parent'].special == 'root':
            raise forms.ValidationError(
                _("Only categories can use Root Category as their parent."))
        if node_role == 'redirect' and not cleaned_data['redirect']:
            raise forms.ValidationError(
                _("You have to define redirection URL"))

        return cleaned_data
Esempio n. 19
0
class CategoryForm(Form, CleanAttrsMixin):
    parent = False
    perms = False
    name = forms.CharField(
        label=_("Category Name"),
        max_length=255,
        validators=[
            validate_sluggable(
                _("Category name must contain alphanumeric characters."),
                _("Category name is too long."))
        ])
    description = forms.CharField(label=_("Category Description"),
                                  widget=forms.Textarea,
                                  required=False)
    closed = forms.BooleanField(label=_("Closed Category"),
                                widget=YesNoSwitch,
                                required=False)
    style = forms.CharField(
        label=_("Category Style"),
        help_text=
        _('You can add custom CSS classess to this category, to change way it looks on board index.'
          ),
        max_length=255,
        required=False)
    attrs = forms.CharField(
        label=_("Category Attributes"),
        help_text=
        _('Custom templates can check categories for predefined attributes that will change way they are rendered.'
          ),
        max_length=255,
        required=False)
    show_details = forms.BooleanField(
        label=_("Show Subforums Details"),
        help_text=
        _('Allows you to prevent this category subforums from displaying statistics, last post data, etc. ect. on forums lists.'
          ),
        widget=YesNoSwitch,
        required=False,
        initial=True)

    layout = (
        (
            _("Basic Options"),
            (
                ('parent', {
                    'label': _("Category Parent")
                }),
                ('perms', {
                    'label': _("Copy Permissions from")
                }),
                ('name', {
                    'label': _("Category Name")
                }),
                ('description', {
                    'label': _("Category Description")
                }),
                ('closed', {
                    'label': _("Closed Category")
                }),
            ),
        ),
        (
            _("Display Options"),
            (
                ('attrs', {
                    'label':
                    _("Category Attributes"),
                    'help_text':
                    _('Custom templates can check categories for predefined attributes that will change way they are rendered.'
                      )
                }),
                ('show_details', {
                    'label':
                    _("Show Subforums Details"),
                    'help_text':
                    _('Allows you to prevent this category subforums from displaying statistics, last post data, etc. ect. on forums lists.'
                      )
                }),
                ('style', {
                    'label':
                    _("Category Style"),
                    'help_text':
                    _('You can add custom CSS classess to this category, to change way it looks on board index.'
                      )
                }),
            ),
        ),
    )

    def finalize_form(self):
        self.add_field(
            'perms',
            TreeNodeChoiceField(
                label=_("Copy Permissions from"),
                widget=forms.Select,
                queryset=Forum.objects.get(special='root').get_descendants(),
                level_indicator=u'- - ',
                required=False,
                empty_label=_("Don't copy permissions")))
Esempio n. 20
0
class RankForm(Form):
    name = forms.CharField(
        max_length=255,
        validators=[
            validate_sluggable(
                _("Rank name must contain alphanumeric characters."),
                _("Rank name is too long."))
        ])
    description = forms.CharField(widget=forms.Textarea, required=False)
    title = forms.CharField(max_length=255, required=False)
    style = forms.CharField(max_length=255, required=False)
    special = forms.BooleanField(widget=YesNoSwitch, required=False)
    as_tab = forms.BooleanField(widget=YesNoSwitch, required=False)
    on_index = forms.BooleanField(widget=YesNoSwitch, required=False)
    criteria = forms.CharField(
        max_length=255,
        initial='0',
        validators=[
            RegexValidator(regex='^(\d+)(%?)$',
                           message=_('This is incorrect rank match rule.'))
        ],
        required=False)
    roles = False

    layout = (
        (_("Basic Rank Options"), (
            ('name', {
                'label':
                _("Rank Name"),
                'help_text':
                _("Rank Name is used to identify rank in Admin Control Panel and is used as page and tab title if you decide to make this rank act as tab on users list."
                  )
            }),
            ('description', {
                'label':
                _("Rank Description"),
                'help_text':
                _("If this rank acts as tab on users list, here you can enter optional description that will be displayed above list of users with this rank."
                  )
            }),
            ('as_tab', {
                'label':
                _("As Tab on Users List"),
                'help_text':
                _("Should this rank have its own page on users list, containing rank's description and list of users that have it? This is good option for rank used by forum team members or members that should be visible and easily reachable."
                  )
            }),
            ('on_index', {
                'label':
                _("Display members online"),
                'help_text':
                _("Should users online with this rank be displayed on board index?"
                  )
            }),
        )),
        (_("Rank Roles"), (('roles', {
            'label':
            _("Rank Roles"),
            'help_text':
            _("You can grant users with this rank extra roles to serve either as rewards or signs of trust to active members."
              )
        }), )),
        (_("Rank Looks"), (
            ('title', {
                'label':
                _("Rank Title"),
                'help_text':
                _("Short description of rank's bearer role in your community.")
            }),
            ('style', {
                'label':
                _("Rank CSS Class"),
                'help_text':
                _("Optional CSS class that will be added to different elements displaying rank's owner or his content, allowing you to make them stand out from other members."
                  )
            }),
        )),
        (
            _("Rank Attainability"),
            (
                ('special', {
                    'label':
                    _("Special Rank"),
                    'help_text':
                    _("Special ranks are ignored during updates of user ranking, making them unattainable without admin ingerention."
                      )
                }),
                ('criteria', {
                    'label':
                    _("Rank Criteria"),
                    'help_text':
                    _("This setting allows you to limit number of users that can attain this rank. Enter 0 to assign this rank to all members (good for default rank). To give this rank to 10% of most active members, enter \"10%\". To give this rank to 10 most active members, enter \"10\". This setting is ignored for special ranks as they don't participate in user's ranking updates."
                      )
                }),
            ),
        ),
    )

    def finalize_form(self):
        if self.request.user.is_god():
            self.fields['roles'] = forms.ModelMultipleChoiceField(
                widget=forms.CheckboxSelectMultiple,
                queryset=Role.objects.order_by('name').all(),
                required=False)
        else:
            self.fields['roles'] = forms.ModelMultipleChoiceField(
                widget=forms.CheckboxSelectMultiple,
                queryset=Role.objects.filter(
                    protected__exact=False).order_by('name').all(),
                required=False)
Esempio n. 21
0
 def finalize_form(self):
     super(NewThreadForm, self).finalize_form()
     self.add_field('thread_name', forms.CharField(label=_("Thread Name"),
                                                   max_length=settings.thread_name_max,
                                                   validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
                                                                                  _("Thread name is too long. Try shorter name."))]))
Esempio n. 22
0
 def finalize_form(self):
     super(NewThreadForm, self).finalize_form()
     self.layout[0][1].append(('thread_name', {'label': _("Thread Name")}))
     self.fields['thread_name'] = forms.CharField(max_length=self.request.settings['thread_name_max'],
                                                  validators=[validate_sluggable(_("Thread name must contain at least one alpha-numeric character."),
                                                                                 _("Thread name is too long. Try shorter name."))])