コード例 #1
0
ファイル: fileadmin.py プロジェクト: tbikeev/Flask-SuperAdmin
    def validate_upload(self, field):
        if not self.upload.has_file():
            raise wtf.ValidationError(gettext('File required.'))

        filename = self.upload.data.filename

        if not self.admin.is_file_allowed(filename):
            raise wtf.ValidationError(gettext('Invalid file type.'))
コード例 #2
0
    def validate_username(form, field):
        user = User.by_username(field.data)
        if not user:
            raise wtf.ValidationError('No such user exists.')

        if reset.count_tokens(user) >= 5:
            raise wtf.ValidationError(
                'You may not reset your password more than 5 times'
                ' in one day.')
コード例 #3
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def new_channel(u, p):
    if p.owner.id != g.user.id:
        # Project isn't public and the viewer isn't the project owner.
        # (403 Forbidden)
        return abort(403)

    form = ChannelDetailsForm()
    if form.validate_on_submit():
        host = form.host.data.strip().lower()
        channel = form.channel.data.strip().lower()

        # Make sure this isn't a duplicate channel before we create it.
        c = Channel.query.filter_by(host=host,
                                    channel=channel,
                                    project_id=p.id).first()
        if not c:
            c = Channel.new(channel,
                            host,
                            port=form.port.data,
                            ssl=form.ssl.data,
                            public=form.public.data)
            p.channels.append(c)
            db.session.add(c)
            db.session.commit()
            return redirect(url_for('.details', p=p.name, u=u.username))
        else:
            form.channel.errors = [
                wtf.ValidationError(
                    'You cannot have a project in the same channel twice.')
            ]

    return render_template('new_channel.html', project=p, form=form)
コード例 #4
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def edit_project(u, p):
    """
    Edit an existing project.
    """
    if p.owner.id != g.user.id:
        # Project isn't public and the viewer isn't the project owner.
        # (403 Forbidden)
        return abort(403)

    form = ProjectDetailsForm(obj=p)
    if form.validate_on_submit():
        old_p = Project.by_name_and_owner(form.name.data, g.user)
        if old_p and old_p.id != p.id:
            form.name.errors = [
                wtf.ValidationError('Project name must be unique.')
            ]
        else:
            p.name = form.name.data
            p.website = form.website.data
            p.public = form.public.data
            p.full_name = '{0}/{1}'.format(g.user.username, p.name)
            db.session.commit()
            return redirect(url_for('.dashboard', u=u.username))

    return render_template('edit_project.html', project=p, form=form)
コード例 #5
0
ファイル: __init__.py プロジェクト: whitequark/notifico
def new():
    """
    Create a new project.
    """
    form = ProjectDetailsForm()
    if form.validate_on_submit():
        p = Project.by_name_and_owner(form.name.data, g.user)
        if p:
            form.name.errors = [
                wtf.ValidationError('Project name must be unique.')
            ]
        else:
            p = Project.new(form.name.data,
                            public=form.public.data,
                            website=form.website.data)
            p.full_name = '{0}/{1}'.format(g.user.username, p.name)
            g.user.projects.append(p)
            db.session.add(p)

            if p.public:
                # New public projects get added to #commits by default.
                c = Channel.new('#commits',
                                'chat.freenode.net',
                                6667,
                                ssl=False,
                                public=True)
                p.channels.append(c)

            db.session.commit()

            return redirect(url_for('.details', u=g.user.username, p=p.name))

    return render_template('new_project.html', form=form)
コード例 #6
0
def same_password(form, field):
    ''' Check if the data in the field is the same as in the password field.
    '''
    if field.data != form.password.data:
        raise wtf.ValidationError('Both password fields should be equal')
コード例 #7
0
ファイル: __init__.py プロジェクト: whitequark/notifico
 def validate_password(form, field):
     if not User.login(g.user.username, field.data):
         raise wtf.ValidationError('Your password is incorrect.')
コード例 #8
0
ファイル: post.py プロジェクト: hasgeek/hasnew
 def validate_description(self, field):
     if not field.data:
         if not self.url.data:
             raise wtf.ValidationError(
                 "Either a URL or a description must be provided.")
コード例 #9
0
 def validate_password(form, field):
     if not User.login(form.username.data, field.data):
         raise wtf.ValidationError('Incorrect username and/or password.')
コード例 #10
0
    def validate_username(form, field):
        from notifico.views.account import _reserved

        username = field.data.strip().lower()
        if username in _reserved or User.username_exists(username):
            raise wtf.ValidationError('Sorry, but that username is taken.')
コード例 #11
0
ファイル: fileadmin.py プロジェクト: tbikeev/Flask-SuperAdmin
 def validate_name(self, field):
     if not self.regexp.match(field.data):
         raise wtf.ValidationError(gettext('Invalid directory name'))