当前位置: 首页>>代码示例>>Python>>正文


Python Product.set_db_name方法代码示例

本文整理汇总了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)
开发者ID:andrefauth,项目名称:pitchfork,代码行数:33,代码来源:views.py

示例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,
            )
开发者ID:futuernorn,项目名称:pitchfork,代码行数:52,代码来源:views.py


注:本文中的models.Product.set_db_name方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。