本文整理汇总了Python中forms.Form.named_values方法的典型用法代码示例。如果您正苦于以下问题:Python Form.named_values方法的具体用法?Python Form.named_values怎么用?Python Form.named_values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.Form
的用法示例。
在下文中一共展示了Form.named_values方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: categories_edit
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import named_values [as 别名]
def categories_edit(category_id):
try:
category = Category.find_by_id(category_id)
if category:
if request.method == 'GET':
category_dict = category.__dict__
form = Form(category_dict, form_fields)
return render_template('category/edit.html', form=form, category_id=category_id, success=True)
elif request.method == 'POST':
form = Form(request.form, form_fields)
if form.validate():
values = form.named_values()
category.from_dict(values)
category.save()
miner = miner_cls(category)
miners[category_id] = miner
miner.start()
return redirect(url_for('categories'))
else:
return render_template('category/edit.html', form=form, category_id=category_id, success=True)
elif request.method == 'DELETE':
miner = miners[category_id]
miner.stop()
del miners[category_id]
Category.delete(category_id)
return 'Category {} deleted.'.format(category_id), 200
else:
return 'Unsupported request method.', 400
else:
return 'Category {} not found.'.format(category_id), 400
except ValueError, e:
print e
return '{} is not a valid category id.'.format(category_id), 400
示例2: categories_edit
# 需要导入模块: from forms import Form [as 别名]
# 或者: from forms.Form import named_values [as 别名]
def categories_edit(category_id):
try:
category = Category.find_by_id(category_id)
if category:
if request.method == "GET":
category_dict = category.__dict__
form = Form(category_dict, form_fields)
return render_template("category/edit.html", form=form, category_id=category_id, success=True)
elif request.method == "POST":
form = Form(request.form, form_fields)
if form.validate():
values = form.named_values()
category.from_dict(values)
category.save()
miner = miner_cls(category)
miners[category_id] = miner
miner.start()
return redirect(url_for("categories"))
else:
return render_template("category/edit.html", form=form, category_id=category_id, success=True)
elif request.method == "DELETE":
if category_id in miners:
miner = miners[category_id]
miner.stop()
del miners[category_id]
Category.delete(category_id)
return "Category {} deleted.".format(category_id), 200
else:
return "Category {} not present on miner.".format(category_id), 400
else:
return "Unsupported request method.", 400
else:
return "Category {} not found.".format(category_id), 400
except ValueError, e:
print e
return "{} is not a valid category id.".format(category_id), 400