本文整理汇总了Python中forms.ProjectForm.populate_obj方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectForm.populate_obj方法的具体用法?Python ProjectForm.populate_obj怎么用?Python ProjectForm.populate_obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ProjectForm
的用法示例。
在下文中一共展示了ProjectForm.populate_obj方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: edit_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import populate_obj [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)
示例2: create_project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import populate_obj [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)
示例3: project_edit
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import populate_obj [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))
示例4: project_new
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import populate_obj [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)
示例5: project
# 需要导入模块: from forms import ProjectForm [as 别名]
# 或者: from forms.ProjectForm import populate_obj [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)