Пример #1
0
class SigninForm(wtf.Form):
    email = wtf.TextField('email',
                          validators=[
                              wtf.Required(message=u'请填写电子邮件'),
                              wtf.Email(message=u'无效的电子邮件')
                          ])
    password = wtf.PasswordField('password',
                                 validators=[
                                     wtf.Required(message=u'请填写密码'),
                                     wtf.Length(min=5,
                                                max=20,
                                                message=u'密应应为5到20位字符')
                                 ])
    next = wtf.HiddenField('next')
    remember = wtf.BooleanField('remember')

    openid_identifier = wtf.HiddenField('openid_identifier')
    openid_provider = wtf.HiddenField('openid_provider')

    def __init__(self, *args, **kargs):
        wtf.Form.__init__(self, *args, **kargs)
        self.user = None

    def validate(self):
        # 验证邮箱是否注册
        if wtf.Form.validate(self):
            user = get_user(email=self.email.data)
            if not user:
                self.email.errors.append(u'该邮箱尚未在本站注册')
            elif not user.check_password(self.password.data):
                self.password.errors.append(u'密码错误')
            else:
                self.user = user

        return len(self.errors) == 0
Пример #2
0
class CommentForm(wtf.Form):
    reply_to_id = wtf.HiddenField('Parent',
                                  default="",
                                  id="comment_reply_to_id")
    edit_id = wtf.HiddenField('Edit', default="", id="comment_edit_id")
    message = wtf.TextAreaField('Add comment',
                                id="comment_message",
                                validators=[wtf.Required()])
Пример #3
0
class CommentForm(wtf.Form):
    """
    Comment form
    """
    reply_to_id = wtf.HiddenField("Parent",
                                  default='',
                                  id='comment_reply_to_id')
    edit_id = wtf.HiddenField("Edit", default='', id='comment_edit_id')
    message = wtf.TextAreaField("Add comment",
                                id='comment_message',
                                validators=[wtf.Required()])
Пример #4
0
class ActivityForm(RedirectForm):
    title = wtf.TextField(u'活动标题', validators=[ \
            wtf.Required(message=u'请为活动填写一个标题')])
    content = wtf.TextAreaField(u'活动简介', validators=[ \
            wtf.Length(min=10, max=5000, message=u'简介至少10个字')])
    start_time = wtf.TextField(u'开始时间', validators=[ \
            wtf.Required(message=u'需要指定开始时间')])
    end_time = wtf.TextField(u'结束时间', validators=[ \
            wtf.Required(message=u'需要指定结束时间')])
    address = wtf.TextField(u'活动地点')
    latitude = wtf.HiddenField()
    longitude = wtf.HiddenField()
Пример #5
0
class UserMergeForm(wtf.Form):
    user_key = wtf.HiddenField('User Key', [wtf.validators.required()])
    user_keys = wtf.HiddenField('User Keys', [wtf.validators.required()])
    username = wtf.StringField(_('Username'), [wtf.validators.optional()])
    name = wtf.StringField(
        _('Name (merged)'),
        [wtf.validators.required()],
        filters=[util.strip_filter],
    )
    email = wtf.StringField(
        _('Email (merged)'),
        [wtf.validators.optional(),
         wtf.validators.email()],
        filters=[util.email_filter],
    )
Пример #6
0
class FragmentForm(Form):
    """
    A fragment form is like a content form but without a summary or template.
    """
    previous_id = wtf.HiddenField(u"Previous revision")
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    name = wtf.TextField(u"URL name", validators=[wtf.Required(), valid_name])
    content = RichTextField(u"Page content",
                            linkify=False,
                            tinymce_options=tinymce_options,
                            sanitize_tags=richtext_sanitize_tags,
                            sanitize_attributes=richtext_sanitize_attributes)
    properties = DictField(u"Properties")

    def validate_previous_id(self, field):
        if not field.data:
            field.data = None
        else:
            try:
                field.data = int(field.data)
            except ValueError:
                raise wtf.ValidationError(u"Unknown previous revision")

    def validate_name(self, field):
        # TODO
        pass
Пример #7
0
class ContentForm(Form):
    previous_id = wtf.HiddenField(u"Previous revision")
    title = wtf.TextField(u"Title", validators=[wtf.Required()])
    name = wtf.TextField(u"URL name", validators=[wtf.Optional(), valid_name])
    description = wtf.TextAreaField(u"Summary",
                                    description=u"Summary of this page")
    content = RichTextField(u"Page content",
                            linkify=False,
                            buttons1=richtext_buttons1,
                            valid_elements=richtext_valid_elements,
                            sanitize_tags=richtext_sanitize_tags,
                            sanitize_attributes=richtext_sanitize_attributes)
    template = wtf.TextField(
        "Template",
        validators=[wtf.Required()],
        default='page.html',
        description=u"Template with which this page will be rendered.")
    properties = DictField(u"Properties")

    def validate_previous_id(self, field):
        if not field.data:
            field.data = None
        else:
            try:
                field.data = int(field.data)
            except ValueError:
                raise wtf.ValidationError("Unknown previous revision")

    def validate_name(self, field):
        # TODO
        pass
Пример #8
0
class VideoActionForm(Form):
    action = wtf.HiddenField(
        "Action", validators=[wtf.Required("You must specify an action")])

    def validate_action(self, field):
        if field.data not in ['star', 'queue', 'like', 'dislike']:
            raise wtf.ValidationError("Unknown action requested")
Пример #9
0
class EventForm(Form):
    """Form to create or edit an event."""

    name = wtf.TextField('Name',
                         validators=[
                             wtf.Required(),
                             wtf.Length(max=200),
                         ])
    starts_at = wtf.DateTimeField('When', format='%Y-%m-%d %H:%M')
    venue = wtf.TextField('Where', validators=[
        wtf.Length(max=200),
    ])
    description = wtf.TextAreaField('What')
    contacts_invited_ids_str = wtf.HiddenField()
Пример #10
0
class SignupForm(wtf.Form):
    email = wtf.TextField('email',
                          validators=[
                              wtf.Required(message=u'请填写电子邮件'),
                              wtf.Email(message=u'无效的电子邮件')
                          ])
    nickname = wtf.TextField('nickname',
                             validators=[
                                 wtf.Required(message=u'请填写昵称'),
                                 wtf.Length(min=2,
                                            max=20,
                                            message=u'昵称应为2到20字符')
                             ])
    password = wtf.PasswordField('password',
                                 validators=[
                                     wtf.Required(message=u'请填写密码'),
                                     wtf.Length(min=5,
                                                max=20,
                                                message=u'密码应为5到20位字符')
                                 ])
    repassword = wtf.PasswordField('repassword',
                                   validators=[
                                       wtf.Required(message=u'请填写确认密码'),
                                       wtf.EqualTo('password',
                                                   message=u'两次输入的密码不一致')
                                   ])
    next = wtf.HiddenField('next')

    def __init__(self, *args, **kargs):
        wtf.Form.__init__(self, *args, **kargs)
        self.user = None

    def validate(self):
        wtf.Form.validate(self)

        # 验证邮箱是否注册
        if not self.email.errors:
            user = get_user(email=self.email.data)
            user and self.email.errors.append(u'该邮箱已被注册')

        self.user = User(email=self.email.data,
                         nickname=self.nickname.data,
                         openids=[
                             UserOpenID(provider=session['openid_provider'],
                                        openid=session['current_openid'])
                         ])
        self.user.set_password(self.password.data)
        self.user.info = UserInfo()

        return len(self.errors) == 0
Пример #11
0
class SignInForm(wtf.Form):

    login = wtf.TextField('Login name',
                          validators=[
                              wtf.Required(),
                              wtf.Length(2, 45),
                              wtf.Regexp(User.LOGIN_PATTERN)
                          ])
    password = wtf.PasswordField('Password', validators=[wtf.Required()])
    return_url = wtf.HiddenField(validators=[wtf.Optional()])
    submit = wtf.SubmitField('Login')

    def validate_login(form, field):
        if g.session.query(User).filter_by(login=field.data).count() < 1:
            raise wtf.ValidationError('There is no {0}.'.format(field.data))

    def validate_password(form, field):
        try:
            user = g.session.query(User).filter_by(login=form.login.data)[0]
        except IndexError:
            pass
        else:
            if user.password != field.data:
                raise wtf.ValidationError('Incorrect password.')
Пример #12
0
class DeleteCommentForm(wtf.Form):
    comment_id = wtf.HiddenField('Comment', validators=[wtf.Required()])
Пример #13
0
class DeleteCollectionForm(InvenioBaseForm):
    """
    Form to confirm deletion of a collection:
    """
    delete = wtf.HiddenField(default='yes', validators=[validators.required()])