本文整理匯總了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