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.'))
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.')
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)
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)
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)
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')
def validate_password(form, field): if not User.login(g.user.username, field.data): raise wtf.ValidationError('Your password is incorrect.')
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.")
def validate_password(form, field): if not User.login(form.username.data, field.data): raise wtf.ValidationError('Incorrect username and/or password.')
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.')
def validate_name(self, field): if not self.regexp.match(field.data): raise wtf.ValidationError(gettext('Invalid directory name'))