本文整理汇总了Python中formalchemy.FieldSet.validate方法的典型用法代码示例。如果您正苦于以下问题:Python FieldSet.validate方法的具体用法?Python FieldSet.validate怎么用?Python FieldSet.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类formalchemy.FieldSet
的用法示例。
在下文中一共展示了FieldSet.validate方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [as 别名]
def post(self):
fs = FieldSet(self.instance,
data=self.request.POST)
if fs.validate():
fs.sync()
self.session.flush()
return HTTPFound(location=fs.model.getUrl())
示例2: object_edit
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [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)
示例3: save
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [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
示例4: new
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [as 别名]
def new(self, req, model_name):
model = self.model.get_model_or_404(model_name)
if req.method == 'POST':
item = model()
fs = FieldSet(item, session=session, data=req.form)
if fs.validate():
fs.sync()
item.save()
session.commit()
return self.redirect_to('list', model_name=model_name)
else:
fs = FieldSet(model, session=session)
return self.render_response('_admin/new.jinja',
item=None, model_name=model_name, fs=fs)
示例5: edit
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [as 别名]
def edit(self, req, model_name, id):
model = self.model.get_model_or_404(model_name)
item = model.query.get(id)
if req.method == 'POST':
fs = FieldSet(item, data=req.form)
if fs.validate():
fs.sync()
item.save()
session.commit()
return self.redirect_to('list', model_name=model_name)
else:
fs = FieldSet(item)
return self.render_response('_admin/new.jinja',
item=item, model_name=model_name, fs=fs, crumbs=[model_name, 'Edit'])
示例6: edit
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [as 别名]
def edit(request):
model = meta.__dict__.get(request.matchdict["model"])
if "id" in request.matchdict:
obj = request.db.query(model).filter(model.id==request.matchdict["id"]).first()
fs = FieldSet(obj, request=request)
else:
fs = FieldSet(model, session=request.db, request=request)
if "POST"==request.environ.get("REQUEST_METHOD", "").upper() and request.POST:
if fs.validate():
request.db.add(fs.model)
fs.sync()
return HTTPFound(location=request.route_url("list", model=request.matchdict["model"]))
return { 'fs': fs }
示例7: saveedit
# 需要导入模块: from formalchemy import FieldSet [as 别名]
# 或者: from formalchemy.FieldSet import validate [as 别名]
def saveedit(request):
model = meta.__dict__.get(request.matchdict["model"])
if "id" in request.matchdict:
obj = request.db.query(model).filter(model.id==request.matchdict["id"]).first()
fs = FieldSet(obj, request=request)
else:
fs = FieldSet(model, session=request.db, request=request)
if fs.validate():
request.db.add(fs.model)
fs.sync()
else:
return { "fs": fs }
return HTTPFound(location=request.route_url("list", model=request.matchdict["model"]))