本文整理汇总了Python中models.Product.set_db_name方法的典型用法代码示例。如果您正苦于以下问题:Python Product.set_db_name方法的具体用法?Python Product.set_db_name怎么用?Python Product.set_db_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.set_db_name方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_settings
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import set_db_name [as 别名]
def manage_settings(self, product):
product_data = self.retrieve_product(product)
if type(product_data) is str:
title = "%s Manage Settings" % product.title()
product_data = None
form = forms.ManageProduct()
else:
title = "%s Manage Settings" % product_data.title
form = forms.ManageProduct(obj=product_data)
if request.method == "POST" and form.validate_on_submit():
to_save = Product(request.form.to_dict())
if product_data and product_data.db_name:
to_save.db_name = product_data.db_name
to_save.groups = product_data.groups
else:
to_save.set_db_name()
g.db.api_settings.update({}, {"$set": {product: to_save.__dict__}})
if to_save.active:
g.db.api_settings.update({}, {"$addToSet": {"active_products": product}})
else:
g.db.api_settings.update({}, {"$pull": {"active_products": product}})
flash("Product was successfully updated", "success")
return redirect("/%s/manage" % product)
else:
if request.method == "POST":
flash("Form was not saved successfully", "error")
return render_template("manage/manage_product.html", title=title, form=form, product=product_data)
示例2: manage_settings
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import set_db_name [as 别名]
def manage_settings(self, product):
product_data = self.retrieve_product(product)
if type(product_data) is str:
title = "%s Manage Settings" % product.title()
product_data = None
form = forms.ManageProduct()
else:
title = "%s Manage Settings" % product_data.title
form = forms.ManageProduct(obj=product_data)
if request.method == 'POST' and form.validate_on_submit():
to_save = Product(request.form.to_dict())
if product_data and product_data.db_name:
to_save.db_name = product_data.db_name
to_save.groups = product_data.groups
else:
to_save.set_db_name()
g.db.api_settings.update(
{}, {
'$set': {
product: to_save.__dict__
}
}
)
if to_save.active:
g.db.api_settings.update(
{}, {
'$addToSet': {'active_products': product}
}
)
else:
g.db.api_settings.update(
{}, {
'$pull': {'active_products': product}
}
)
flash('Product was successfully updated', 'success')
return redirect('/%s/manage' % product)
else:
if request.method == 'POST':
flash('Form was not saved successfully', 'error')
return render_template(
'manage/manage_product.html',
title=title,
form=form,
product=product_data,
)