本文整理汇总了Python中forms.ProjectForm.validate_on_submit方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm.validate_on_submit方法的具体用法?Python ProjectForm.validate_on_submit怎么用?Python ProjectForm.validate_on_submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProjectForm
的用法示例。
在下文中一共展示了ProjectForm.validate_on_submit方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def create_project():
config.reload()
form = ProjectForm()
ds_forms = dict([
(cls.populates, cls()) for cls in DataSourceForm.__subclasses__()])
form.datasource_type.choices = [
(cls.populates, cls.name) for cls in DataSourceForm.__subclasses__()]
form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))
new_project = Project()
if form.validate_on_submit():
form.populate_obj(new_project)
ds_form = ds_forms[form.datasource_type.data]
if ds_form.validate():
new_project.datasource = \
getattr(models, form.datasource_type.data)()
ds_form.populate_obj(new_project.datasource)
db.session.add(new_project)
db.session.commit()
flash("New project successfully created.")
return redirect(url_for('view_project', id=new_project.id))
return render_template("project/create.html",
form=form, ds_forms=ds_forms, project=new_project)
示例2: edit_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def edit_project(id):
project = Project.query.get_or_404(id)
ds_forms = dict([
(cls.populates, cls()) for cls in DataSourceForm.__subclasses__()])
for populates, ds_form in ds_forms.items():
if populates == project.datasource.__class__.__name__:
ds_forms[populates] = ds_form.__class__(obj=project.datasource)
current_ds_type = populates
form = ProjectForm(obj=project, datasource_type=current_ds_type)
form.datasource_type.choices = [
(cls.populates, cls.name) for cls in DataSourceForm.__subclasses__()]
form.datasource_type.choices.insert(0, (None, "-- Select Data Source --"))
if form.validate_on_submit():
form.populate_obj(project)
ds_form = ds_forms[form.datasource_type.data]
if ds_form.validate():
project.datasource = getattr(models, form.datasource_type.data)()
ds_form.populate_obj(project.datasource)
db.session.add(project)
db.session.commit()
flash("Project %s successfully updated." % project.name)
return redirect(url_for('view_project', id=project.id))
return render_template("project/edit.html",
form=form, ds_forms=ds_forms, project=project)
示例3: setting_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def setting_project():
# 表格信息区
projects = db.engine.execute(SQL['PROJECT_INFO'])
project_choices = [(p.id, p.project_name) for p in Project.query.order_by('id')]
user_choices = [(p.id, p.user_name) for p in User.query.filter(User.enable == 1).order_by('id')]
# 增加项目区
add_form = ProjectForm()
add_form.project_manager.choices = user_choices
if add_form.validate_on_submit():
if g.user.role == 0:
try:
new_project = Project(add_form.project_name.data, add_form.project_manager.data,
add_form.build_year.data, add_form.status.data)
db.session.add(new_project)
db.session.commit()
log('project', '增加项目', new_project.id, new_project.project_name, '成功')
flash("项目添加成功!")
except Exception, e:
flash("无法添加项目!")
print Exception, e
return render_template('setting-project.html', data=projects, user_choices=user_choices,
status_choices=PROJECT_STATUS, add_form=add_form,
project_choices=project_choices, atr='show')
else:
flash("无权限操作!")
示例4: add_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def add_project():
form = ProjectForm()
if request.method == 'POST':
if form.validate_on_submit():
new_project = Projects(form.name.data, form.category.data, form.info.data, form.slug.data,
form.status.data, github=form.github.data, url=form.url.data)
db.session.add(new_project)
db.session.commit()
flash('New project added')
else:
flash('Validation failed')
return render_template('new.html', form=form)
示例5: edit
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def edit(name):
form = ProjectForm()
if request.method == 'POST':
if form.validate_on_submit():
selected_project = Projects.query.filter(Projects.slug == name).first()
selected_project.update(form)
db.session.commit()
flash('Project edited')
else:
flash('Validation error')
return render_template('edit.html',
project=Projects.query.filter(Projects.slug == name).first(),
form=form)
示例6: project_new
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def project_new():
project = Project()
form = ProjectForm(request.form, project)
if form.validate_on_submit():
counter = Counter.objects(id_for="project")[0]
counter.set_next_id()
counter.save()
form.populate_obj(project)
project.number = counter.number
project.save()
return redirect('/projects/')
return render_template('projects_create.html',
project=project,
form=form)
示例7: project_setting
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def project_setting(project_id):
project = Project.query.get(project_id)
if current_user.id != project.creator_id:
abort(404)
form = ProjectForm(user=current_user, team=project.team, project=project, team_id=project.team.id,
name=project.name, subject=project.subject)
form.team_id.choices = [(g.id, g.name) for g in current_user.teams]
if form.validate_on_submit():
if request.form.get('delete'):
project.status = 1
db.session.add(project)
db.session.commit()
return redirect(url_for('run'))
return redirect(url_for('project_index', project_id=form.project.id))
return render_template('project/form.html', form=form)
示例8: project_create
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def project_create():
form = ProjectForm()
if form.validate_on_submit():
new_project = Project(
title=form.title.data,
branch=form.branch.data,
user_id=current_user.get_id(),
repo_url=form.repo_url.data
)
db.session.add(new_project)
db.session.commit()
flash('Project has been created successfully.', 'success')
return redirect(url_for('project', project_id=new_project.id))
return render_template('project/form.html', form=form, action_url=url_for('project_create'))
示例9: index
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def index():
form = ProjectForm()
if form.validate_on_submit():
project_name = request.form['name']
api_type = request.form['api_type']
project = Project(
name=project_name,
api_type=api_type,
created_by=current_user.id
)
db.session.add(project)
db.session.commit()
flash('Project Created')
return redirect(url_for('main_site_index.index'))
return render_template('main/api_auth.html', form=form)
示例10: project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def project(id_project=None):
from forms import ProjectForm
if id_project != None:
project = Project.query.get(id_project)
action = "Save"
else:
project = Project()
action = "Create"
form = ProjectForm(obj=project)
if form.validate_on_submit():
form.populate_obj(project)
project.users.append(current_user)
db.session.add(project)
db.session.commit()
return redirect('/projects')
return render_template('project/form.html', form=form, action=action)
示例11: newproject
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def newproject():
error = None
form = ProjectForm()
if request.method == 'POST':
if form.validate_on_submit():
print 'validated'
new_project = Project(
form.subject.data,
form.discription.data,
form.duedate.data,
form.finished.data,
form.download_file.data,
)
db.session.add(new_project)
db.session.commit()
flash(u'پروژه ثبت شد ممد!')
else:
print 'not!'
return render_template('newproject.html', form=form, error=error)
示例12: create_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def create_project(record_id=False):
form = ProjectForm()
if form.validate_on_submit():
values = {
'name': form.name.data,
'description': form.description.data,
'color': form.color.data,
'date': form.date.data,
}
if current_user.data.get('id') and not record_id:
values['user_id'] = current_user.data.get('id')
if record_id:
table_registry.projects.write([record_id], values)
else:
table_registry.projects.create(values)
return json.dumps({'redirect': url_for('home')})
elif record_id:
project_data = table_registry.projects.search_read([['id', '=', record_id]])[0]
form.name.data = project_data['name']
form.description.data = project_data['description']
form.color.data = project_data['color']
form.date.data = project_data['date'].strftime('%m/%d/%Y %I:%M %p')
return render_template('backend/project_model.html', form=form, record_id=record_id and str(record_id))
示例13: project_create
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import validate_on_submit [as 别名]
def project_create():
form = ProjectForm(user=current_user, team_id=request.args.get('team_id'))
form.team_id.choices = [(g.id, g.name) for g in current_user.teams]
if form.validate_on_submit():
return redirect(url_for('project_index', project_id=form.project.id))
return render_template('project/form.html', form=form)