Example #1
0
 def init(cls, choices, selected, node=None, **kwargs):
     cls.parent_name = SelectMultipleField(
         '父节点',
         [],
         choices=choices,
     )
     cls.name = TextField(
         '节点名',
         [
             validators.Required(),
             validators.Length(min=1, max=16),
         ],
     )
     cls.urlname = TextField('节点地址', [
         validators.Required(),
         validators.Length(min=2, max=32),
         validators.Regexp(
             '^[a-zA-Z0-9_]+$',
             message='节点地址只能包含英文字母和数字',
         ),
     ],
                             description='节点地址只能包含英文字母和数字')
     cls.description = TextAreaField('描述', [
         validators.Length(min=0, max=3000),
     ],
                                     description='节点描述')
     cls.style = TextAreaField('样式', [
         validators.Length(min=0, max=1000),
     ],
                               description='节点样式')
     nf = cls(kwargs)
     nf.parent_name.data = selected
     nf.node = node
     return nf
Example #2
0
 def init(choices, selected):
     NodeForm.parent_name = SelectMultipleField(
         '父节点',
         [],
         choices=choices,
     )
     NodeForm.name = TextField(
         '节点名',
         [
             validators.Required(),
             validators.Length(min=1, max=16),
         ],
     )
     NodeForm.urlname = TextField('节点地址', [
         validators.Required(),
         validators.Length(min=2, max=32),
         validators.Regexp(
             '^[a-zA-Z0-9_]+$',
             message='节点地址只能包含英文字母和数字',
         ),
     ],
                                  description='节点地址只能包含英文字母和数字')
     NodeForm.description = TextAreaField('描述', [
         validators.Length(min=0, max=3000),
     ],
                                          description='节点描述')
     nf = NodeForm()
     nf.parent_name.data = selected
     return nf
Example #3
0
class SignupForm(BaseForm):
    name = TextField('用户名', [
        validators.Required(),
        validators.Length(min=4, max=16),
        validators.Regexp(
            '^[a-zA-Z0-9]+$',
            message='用户名只能包含英文字母和数字',
        ),
    ],
                     description='用户名只能包含英文字母和数字')
    email = TextField('邮箱', [
        validators.Required(),
        validators.Length(min=4, max=30),
        validators.Email(),
    ],
                      description='邮箱用于管理帐户')
    password = PasswordField('密码', [
        validators.Required(),
        validators.Length(min=6, max=24),
    ],
                             description='密码最少 6 字节')
    password2 = PasswordField(
        '密码确认',
        [
            validators.Required(),
            validators.Length(min=6, max=24),
        ],
    )

    @db_session
    def validate_name(self, field):
        data = field.data.lower()
        if data in config.forbidden_name_list or User.get(name=data):
            raise ValidationError('此用户名已注册')

    @db_session
    def validate_email(self, field):
        data = field.data.lower()
        if User.get(email=data):
            raise ValidationError('此邮箱已注册')

    def validate_password(self, field):
        if field.data != self.password2.data:
            raise ValidationError('密码不匹配')

    def save(self, role=None):
        data = self.data
        data.pop('password2')
        user = User.init(**data)
        if role:
            user.role = role
        user.save()
        return user
Example #4
0
 def init(choices, selected, args=None, node=None):
     NodeEditForm.parent_name = SelectMultipleField(
         '父节点',
         [],
         choices=choices,
     )
     NodeEditForm.name = TextField(
         '节点名',
         [
             validators.Required(),
             validators.Length(min=1, max=16),
         ],
     )
     NodeEditForm.urlname = TextField('节点地址', [
         validators.Required(),
         validators.Length(min=2, max=32),
         validators.Regexp(
             '^[a-zA-Z0-9_]+$',
             message='节点地址只能包含英文字母和数字',
         ),
     ],
                                      description='节点地址只能包含英文字母和数字')
     NodeEditForm.description = TextAreaField('描述', [
         validators.Length(min=0, max=3000),
     ],
                                              description='节点描述')
     NodeEditForm.style = TextAreaField('样式', [
         validators.Length(min=0, max=1000),
     ],
                                        description='节点样式')
     if args:
         nf = NodeEditForm(args)
     else:
         nf = NodeEditForm()
     nf.parent_name.data = selected
     nf.node = node
     return nf
Example #5
0
    def init(user=None, args=None):
        nickname = TextField('昵称', [
            validators.Required(),
            validators.Length(min=4, max=16),
        ],
                             description='您还有 %s 次修改昵称的机会' %
                             user.edit_nickname_count)
        urlname = TextField('域名', [
            validators.Required(),
            validators.Length(min=4, max=30),
            validators.Regexp(
                '^[a-zA-Z0-9_]+$',
                message='域名只能包含英文字母和数字',
            ),
        ],
                            description='您还有 %s 次修改域名的机会' %
                            user.edit_urlname_count)
        address = TextField(
            '城市',
            [
                validators.Length(min=0, max=200),
            ],
        )
        website = TextField(
            '网址',
            [
                validators.Length(min=0, max=200),
            ],
        )
        description = TextAreaField(
            '简介',
            [
                validators.Length(min=0, max=10000),
            ],
        )
        style = TextAreaField(
            '样式',
            [
                validators.Length(min=0, max=1000),
            ],
        )
        SettingForm.nickname = nickname
        SettingForm.urlname = urlname
        SettingForm.address = address
        SettingForm.website = website
        SettingForm.description = description
        SettingForm.style = style

        if not args:
            if user:
                args = {
                    'nickname': [user.nickname],
                    'urlname': [user.urlname],
                    'address': [user.address],
                    'website': [user.website],
                    'description': [user.description],
                    'style': [user.style]
                }
                sf = SettingForm(args)
                sf.edit_nickname_count = user.edit_nickname_count
                sf.edit_urlname_count = user.edit_urlname_count
                sf.user = user
            else:
                sf = SettingForm()
        else:
            if user:
                sf = SettingForm(args)
                sf.edit_nickname_count = user.edit_nickname_count
                sf.edit_urlname_count = user.edit_urlname_count
                sf.user = user
            else:
                sf = SettingForm(args)
        return sf
Example #6
0
class SettingForm(BaseForm):
    nickname = TextField(
        '昵称',
        [
            validators.Required(),
            validators.Length(min=4, max=16),
        ],
    )
    urlname = TextField('域名', [
        validators.Required(),
        validators.Length(min=4, max=30),
        validators.Regexp(
            '^[a-zA-Z0-9_]+$',
            message='域名只能包含英文字母和数字',
        ),
    ],
                        description='让您的域名具有个性')
    address = TextField(
        '城市',
        [
            validators.Length(min=0, max=200),
        ],
    )
    website = TextField(
        '网址',
        [
            validators.Length(min=1, max=200),
        ],
    )
    description = TextAreaField(
        '简介',
        [
            validators.Length(min=1, max=10000),
        ],
    )
    style = TextAreaField(
        '样式',
        [
            validators.Length(min=0, max=1000),
        ],
    )

    @staticmethod
    def init(user=None, args=None):
        nickname = TextField('昵称', [
            validators.Required(),
            validators.Length(min=4, max=16),
        ],
                             description='您还有 %s 次修改昵称的机会' %
                             user.edit_nickname_count)
        urlname = TextField('域名', [
            validators.Required(),
            validators.Length(min=4, max=30),
            validators.Regexp(
                '^[a-zA-Z0-9_]+$',
                message='域名只能包含英文字母和数字',
            ),
        ],
                            description='您还有 %s 次修改域名的机会' %
                            user.edit_urlname_count)
        address = TextField(
            '城市',
            [
                validators.Length(min=0, max=200),
            ],
        )
        website = TextField(
            '网址',
            [
                validators.Length(min=0, max=200),
            ],
        )
        description = TextAreaField(
            '简介',
            [
                validators.Length(min=0, max=10000),
            ],
        )
        style = TextAreaField(
            '样式',
            [
                validators.Length(min=0, max=1000),
            ],
        )
        SettingForm.nickname = nickname
        SettingForm.urlname = urlname
        SettingForm.address = address
        SettingForm.website = website
        SettingForm.description = description
        SettingForm.style = style

        if not args:
            if user:
                args = {
                    'nickname': [user.nickname],
                    'urlname': [user.urlname],
                    'address': [user.address],
                    'website': [user.website],
                    'description': [user.description],
                    'style': [user.style]
                }
                sf = SettingForm(args)
                sf.edit_nickname_count = user.edit_nickname_count
                sf.edit_urlname_count = user.edit_urlname_count
                sf.user = user
            else:
                sf = SettingForm()
        else:
            if user:
                sf = SettingForm(args)
                sf.edit_nickname_count = user.edit_nickname_count
                sf.edit_urlname_count = user.edit_urlname_count
                sf.user = user
            else:
                sf = SettingForm(args)
        return sf

    def validate_nickname(self, field):
        data = field.data
        if data != self.user.nickname:
            if self.user.edit_nickname_count < 1:
                raise ValidationError('您已经没有修改昵称的机会')

    def validate_urlname(self, field):
        data = field.data
        if data != self.user.urlname:
            if self.user.edit_urlname_count < 1:
                field.data = self.user.urlname
                raise ValidationError('您已经没有修改域名的机会')
            if data in config.forbidden_name_list or User.get(urlname=data):
                raise ValidationError('此域名已经被占用')

    def save(self, user=None):
        data = self.data
        user = user.update(data)
        return user
Example #7
0
    def init(cls, user=None, **kwargs):
        cls.nickname = TextField('昵称', [
            validators.Required(),
            validators.Length(min=4, max=16),
        ],
                                 description='您还有 %s 次修改昵称的机会' %
                                 user.edit_nickname_count)
        cls.urlname = TextField('域名', [
            validators.Required(),
            validators.Length(min=4, max=30),
            validators.Regexp(
                '^[a-zA-Z0-9_]+$',
                message='域名只能包含英文字母和数字',
            ),
        ],
                                description='您还有 %s 次修改域名的机会' %
                                user.edit_urlname_count)
        cls.address = TextField(
            '城市',
            [
                validators.Length(min=0, max=200),
            ],
        )
        cls.website = TextField(
            '网址',
            [
                validators.Length(min=0, max=200),
            ],
        )
        cls.description = TextAreaField(
            '简介',
            [
                validators.Length(min=0, max=10000),
            ],
        )
        cls.style = TextAreaField(
            '样式',
            [
                validators.Length(min=0, max=1000),
            ],
        )
        cls.site_style = TextAreaField(
            '全站样式',
            [
                validators.Length(min=0, max=1000),
            ],
        )

        if not kwargs and user:
            kwargs = {
                'nickname': [user.nickname],
                'urlname': [user.urlname],
                'address': [user.address],
                'website': [user.website],
                'description': [user.description],
                'style': [user.style],
                'site_style': [user.site_style]
            }

        sf = cls(kwargs)
        if user:
            sf.edit_nickname_count = user.edit_nickname_count
            sf.edit_urlname_count = user.edit_urlname_count
            sf.user = user
        return sf