本文整理汇总了Python中forms.ProjectForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm.validate方法的具体用法?Python ProjectForm.validate怎么用?Python ProjectForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProjectForm
的用法示例。
在下文中一共展示了ProjectForm.validate方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_project2
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def edit_project2(project_id):
if 'email' not in session:
return redirect(url_for('home'))
project_By_ID = project.query.filter_by(id = project_id).first_or_404()
show_project = ProjectForm()
show_project.set_supervisor_choices()
show_project.setFormContentFromProject(project_By_ID)
if request.method == 'POST':
show_project = ProjectForm()
show_project.set_supervisor_choices()
if show_project.validate() == False:
flash('Please fill out everything')
return render_template('edit_project.html', show_project=show_project, projectByID = project_By_ID)
else:
project_By_ID.updateProject(show_project)
db.session.add(project_By_ID)
db.session.commit()
return redirect(url_for('home'))
elif request.method == 'GET':
return render_template('edit_project.html', show_project=show_project, projectByID = project_By_ID)
示例2: form
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def form():
form = ProjectForm()
email = session['email']
project_id = project_nums()
user = User.query.filter_by(email=email).first()
user_id = user.uid
firstname, lastname = user.firstname, user.lastname
if request.method == "POST":
if form.validate() == False:
return render_template('form.html', form=form, firstname=firstname, lastname=lastname)
else:
name = form.groupname.data
goal = form.goal.data
accomplish = form.accomplish.data
friends = form.friends.data
new_user_project = Projects(project_id, name, user_id, goal, accomplish)
if friends:
friends = friends.split(" ")
for i in friends:
friend = None
if "@" in i:
friend = User.query.filter_by(email=i[1:-2]).first()
friend_id = friend.uid
if friend:
new_friend_project = Projects(project_id, name, friend_id, '', '')
db.session.add(new_friend_project)
db.session.commit()
db.session.add(new_user_project)
db.session.commit()
return redirect(url_for('home', firstname = firstname, lastname = lastname))
return render_template("form.html", form=form, firstname=firstname, lastname= lastname)
示例3: create_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def create_project():
if 'email' not in session:
return redirect(url_for('home'))
show_project = ProjectForm()
show_project.set_supervisor_choices()
if request.method == 'POST':
if show_project.validate() == False:
flash('All fields are required.')
return render_template('create_project.html', show_project=show_project)
else:
new_project = project(show_project, session['email'])
db.session.add(new_project)
db.session.commit()
if show_project.file.data.filename:
os.makedirs("Project/files/" + str(newuser.id))
filename = secure_filename(show_project.file.data.filename)
show_project.file.data.save('Project/files/' + str(newuser.id) + "/" + filename)
flash('Project has been created')
return redirect(url_for('create_project'))
elif request.method == 'GET':
return render_template('create_project.html', show_project=show_project)
示例4: add
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def add(self):
form = ProjectForm(csrf_enabled=False)
if form.validate():
project = form.save()
db.session.add(project)
db.session.commit()
return 201, project.id
return 400, form.errors
示例5: add_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def add_project():
form = ProjectForm(request.form)
if not form.validate():
return str(form.errors)
project = Project(form.name.data)
db.session.add(project)
db.session.commit()
return redirect(url_for('index'))
示例6: project_edit
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def project_edit(project_id):
project = Project.query.filter_by(id=project_id).first_or_404()
form = ProjectForm(obj=project)
if request.method == 'POST' and form.validate():
form.populate_obj(project)
db.session.commit()
flash('Project has been updated successfully.', 'success')
return redirect(url_for('project', project_id=project.id))
return render_template('project/form.html', form=form, action_url=url_for('project_edit', project_id=project.id))
示例7: getProject
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def getProject(*args, **kwargs):
"""
获取业务列表
"""
form = ProjectForm(data = kwargs)
if not form.validate():
return dictify(test = {"code": 1}, success = False, msg = u"表单参数有误")
project_id = form.project_id.data
projects = Project.objects.filter(id__in = project_id).values("id", "name")
data = list(projects)
return dictify(test = {"code": 4}, success = True, data = data)
示例8: create_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def create_project():
form = ProjectForm()
if request.method == "GET" and 'project_id' in request.values:
form.name.data = request.values['project_id']
if request.method == "POST":
# At first, we don't want the user to bother with the identifier
# so it will automatically be missing because not displayed into
# the form
# Thus we fill it with the same value as the filled name,
# the validation will take care of the slug
if not form.id.data:
form.id.data = form.name.data
if form.validate():
# save the object in the db
project = form.save()
db.session.add(project)
db.session.commit()
# create the session object (authenticate)
session[project.id] = project.password
session.update()
# send reminder email
g.project = project
message_title = _("You have just created '%(project)s' "
"to share your expenses", project=g.project.name)
message_body = render_template("reminder_mail.%s" %
get_locale().language)
msg = Message(message_title,
body=message_body,
recipients=[project.contact_email])
try:
mail.send(msg)
except SMTPRecipientsRefused:
msg_compl = 'Problem sending mail. '
# TODO: destroy the project and cancel instead?
else:
msg_compl = ''
# redirect the user to the next step (invite)
flash(_("%(msg_compl)sThe project identifier is %(project)s",
msg_compl=msg_compl, project=project.id))
return redirect(url_for(".invite", project_id=project.id))
return render_template("create_project.html", form=form)
示例9: add_projects
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def add_projects():
form = ProjectForm(request.form)
if request.method == 'POST':
if form.validate() == False:
flash('All fields are required.')
return render_template('project_add.html', form=form)
else:
choice = filter(lambda c: c[0] == form.name.data, form.name.choices)[0]
print(choice)
project_abv = choice[0]
project_name = choice[1]
id = create_project(s, name=project_name, short_name=project_abv, user=current_user.id)
if id == -1:
form.name.errors = ["That name isn't unique.",]
return render_template('project_add.html', form=form)
return view_projects()
elif request.method == 'GET':
return render_template('project_add.html', form=form)
示例10: new_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate [as 别名]
def new_project():
form = ProjectForm(request.form)
if request.method == 'POST':
form.repositories.choices = get_repo_list(g.user)
if form.validate():
project = Projects(name=form.name.data, author_id=g.user.id)
db_session.add(project)
db_session.commit()
project.collaborators.append(g.user)
repo_name_list = []
for repo in form.repositories.data:
repo_id, repo_name = repo.split('*')
repo_name_list.append(repo_name)
repository = Repositories(
name=repo_name, github_repo_id=repo_id,
project_id=project.id)
db_session.add(repository)
db_session.commit()
return redirect(url_for('add_labels', project_id=project.id))
# this is for GET request
form.repositories.choices = get_repo_list(g.user)
return render_template(
"new_project.html", form=form, view_url=url_for('new_project'))