本文整理汇总了Python中formalchemy.FieldSet.rebind方法的典型用法代码示例。如果您正苦于以下问题:Python FieldSet.rebind方法的具体用法?Python FieldSet.rebind怎么用?Python FieldSet.rebind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formalchemy.FieldSet
的用法示例。
在下文中一共展示了FieldSet.rebind方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: object_edit
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import rebind [as 别名]
def object_edit(model_slug, model_key=None, **attrs):
if model_slug not in models:
abort(404)
model = models[model_slug]
sk = attrdict()
if model_key:
try: data = model.q.get_by(id=model_key)
except NoData: abort(404)
else:
data = model
sk.session = db
if model_key:
obj = model.q.get_by(id=int(model_key))
else:
obj = None
fields = FieldSet(data, **sk)
_fixup_fs(fields,model_key,attrs)
if request.method == 'POST':
fields.rebind(data=request.form)
if fields.validate():
fields.sync()
next_url = url_for('_admin.object_list', model_slug=model_slug)
return redirect(next_url)
context = {
'model_slug': model_slug,
'model': model,
'fields': fields,
}
template_name = '_admin/edit.html' if model_key else '_admin/new.html'
return render_template(template_name, **context)
示例2: save
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import rebind [as 别名]
def save(self, model, data, session):
fs = FieldSet(model, session=session)
fs.rebind(model, data=data)
if fs.validate():
fs.sync()
return True
#TODO: need to return validation result
return False