Exemplo n.º 1
0
class EditForumForm(Form):

    name = TextField(lazy_gettext(u'Name'),
                     [validators.required(),
                      validators.length(max=160)])
    slug = TextField(lazy_gettext(u'Slug'),
                     [validators.required(),
                      validators.length(max=160)])
    parent = QuerySelectField(lazy_gettext(u'Parent'),
                              query_factory=lambda: Forum.query,
                              get_label='name',
                              allow_blank=True)
    description = TextField(lazy_gettext(u'Description'),
                            [validators.required()],
                            widget=widgets.TextArea())
    tags = AutocompleteField(lazy_gettext(u'Tags'),
                             get_label='name',
                             query_factory=lambda: Tag.query,
                             validators=[validators.length(min=1)])

    def validate_parent(self, field):
        message = lazy_gettext(
            u"You can't choose the forum itself or one of its subforums as parent"
        )
        forum = Forum.query.filter_by(slug=self.slug.data).first()
        forums = Forum.query.filter_by(slug=self.slug.data).subforums()
        if field.data in forums or field.data == forum:
            raise ValidationError(message)
Exemplo n.º 2
0
class AskQuestionForm(Form):

    title = TextField(lazy_gettext(u'Title'),
                      [validators.length(max=160),
                       validators.required()])
    text = TextField(lazy_gettext(u'Text'), [validators.required()],
                     widget=widgets.TextArea())
    tags = AutocompleteField(lazy_gettext(u'Tags'),
                             get_label='name',
                             query_factory=lambda: Tag.query)
Exemplo n.º 3
0
class EditArticleForm(Form):
    title = TextField(_(u'Title'), [validators.required(), validators.length(max=200)])
    intro = TextField(_(u'Intro'), [validators.required()], widget=widgets.TextArea())
    text = TextField(_(u'Text'), [validators.required()], widget=widgets.TextArea())
    public = BooleanField(_(u'Published'))
    tags = AutocompleteField(_(u'Tags'), get_label='name',
                             query_factory=lambda: Tag.query.autoflush(False))
    author = QuerySelectField(_(u'Author'), [validators.required()],
                             query_factory=lambda: User.query.autoflush(False),
                             widget=widgets.Select())
Exemplo n.º 4
0
class LoginForm(Form):
    """Used to log in users."""
    username = TextField(lazy_gettext(u'Username'), [validators.required()])
    password = TextField(lazy_gettext(u'Password'), [validators.required()],
                         widget=widgets.PasswordInput())
    permanent = BooleanField(lazy_gettext(u'Remember me'))

    def __init__(self, auth_system, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.auth_system = auth_system
        if self.auth_system.passwordless:
            del self.password
Exemplo n.º 5
0
class AddEventForm(Form):
    title = TextField(_(u'Title'),
                      [validators.length(max=100),
                       validators.required()])
    text = TextField(_(u'Text'), [validators.required()],
                     widget=widgets.TextArea())
    start = DateTimeField(_(u'Start'), [validators.required()])
    end = DateTimeField(_(u'End'), [validators.required()])
    tags = AutocompleteField(_(u'Tags'),
                             get_label='name',
                             query_factory=lambda: Tag.query.autoflush(False))
    discussion_question = BooleanField(_(u'Create topic for discussion'))
    info_question = BooleanField(_(u'Create topic for further information'))
Exemplo n.º 6
0
    class ChangePasswordForm(Form):

        old_password = PasswordField(lazy_gettext(u'Old Password'),
                                     [validators.required()])
        new_password = PasswordField(lazy_gettext(u'New Password'),
                                     [validators.required()],
                                     default=random_pw,
                                     widget=widgets.PasswordInput(False))
        new_password_confirm = PasswordField(
            lazy_gettext(u'New Password (confirmation)'), [
                validators.equal_to(
                    'new_password',
                    message=lazy_gettext(u'Passwords must match'))
            ],
            default=random_pw,
            widget=widgets.PasswordInput(False))
Exemplo n.º 7
0
 class RegistrationForm(Form):
     username = TextField(
         lazy_gettext(u'Username'),
         [validators.required(),
          validators.is_user(negative=True)])
     email = TextField(lazy_gettext(u'Email'), [
         validators.required(),
         validators.is_user(negative=True, key='email')
     ])
     password = PasswordField(lazy_gettext(u'Password'), [
         validators.required(),
         validators.equal_to('confirm',
                             message=lazy_gettext(u'Passwords must match'))
     ],
                              widget=widgets.PasswordInput(False),
                              default=random_pw)
     confirm = PasswordField(lazy_gettext(u'Repeat Passord'),
                             [validators.required()],
                             widget=widgets.PasswordInput(False),
                             default=random_pw)
     captcha = RecaptchaField(lazy_gettext(u'ReCaptcha'))
Exemplo n.º 8
0
class SearchForm(MagicFilterForm):
    csrf_disabled = True
    dynamic_fields = ['author', 'tags', 'date']

    q = TextField(lazy_gettext(u'Search'), [validators.required()])
    page = IntegerField(lazy_gettext(u'Page'), default=1)

    # dynamc fields
    author = TextField(
        lazy_gettext(u'Author'),
        [validators.optional(), validators.is_user()],
        widget=widgets.AutocompleteWidget('api/core/get_user'))
    tags = AutocompleteField(lazy_gettext(u'Tags'),
                             get_label='name',
                             query_factory=lambda: Tag.query)
    date = DatePeriodField(lazy_gettext(u'Date'))
Exemplo n.º 9
0
class AddPasteForm(Form):
    title = TextField(_(u'Title (optional)'), [validators.length(max=50)])
    text = TextField(_(u'Text'), [validators.required()],
                     widget=widgets.TextArea())
    language = SelectField(_(u'Language'), choices=_get_pygments_lexers())
    parent = HiddenIntegerField(validators=[validators.optional()])
Exemplo n.º 10
0
class AnswerQuestionForm(Form):

    text = TextField(lazy_gettext(u'Text'), [validators.required()],
                     widget=widgets.TextArea())
Exemplo n.º 11
0
class DeactivateProfileForm(Form):
    password = PasswordField(lazy_gettext(u'Password'),
                             [validators.required()],
                             widget=widgets.PasswordInput(False))
Exemplo n.º 12
0
class EditTagForm(Form):
    name = TextField(lazy_gettext(u'Name'), [
        validators.required(),
        validators.length(max=20),
        validators.is_valid_tag_name()
    ])