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


Python ProductForm.validate方法代码示例

本文整理汇总了Python中forms.ProductForm.validate方法的典型用法代码示例。如果您正苦于以下问题:Python ProductForm.validate方法的具体用法?Python ProductForm.validate怎么用?Python ProductForm.validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在forms.ProductForm的用法示例。


在下文中一共展示了ProductForm.validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: share

# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import validate [as 别名]
def share():
    if request.method == 'GET':
        form = ProductForm()
    else:
        form = ProductForm(request.form)
        if form.validate():
            if form.create_product(g.user) is not None:            
                return redirect(url_for('home'))    
    return render_template('share_product.html', form=form)
开发者ID:seayoung1112,项目名称:Cookie,代码行数:11,代码来源:views.py

示例2: ProductHandler

# 需要导入模块: from forms import ProductForm [as 别名]
# 或者: from forms.ProductForm import validate [as 别名]
class ProductHandler(BaseHandler):
    @admin_required
    def get(self, product_id=None, **kwargs):
        """Return a product to edit or an empty form to create"""
        template = 'admin/product/new.html'
        context = {
            'form': self.form,
        }
        # render edit form
        if product_id is not None:
            product = Product.get_by_id(product_id)
            if product:
                self.form = ProductForm(obj=product)
                self.form.tags.data = ', '.join(product.tags)
                context.update({ 'form': self.form })
                template = 'admin/product/edit.html'
            else:
                return redirect('/admin/shop/')
        # render new form
        return self.render_response(template, **context)
    
    @admin_required
    def post(self, product_id=None, **kwargs):
        """Handle submitted form data"""
        # validate form
        if self.form.validate():
            name = self.form.name.data
            description = self.form.description.data
            price = self.form.price.data
            unit = self.form.unit.data
            live = self.form.live.data
            tags = self.form.tags.data
            language = self.form.language.data
            if tags is not None:
                tags = [tag.strip() for tag in tags.split(',') if tag != '']
            # save edit form
            if product_id:
                product = Product.get_by_id(product_id)
                product.name = name
                product.description = description
                product.price = price
                product.unit = unit
                product.live = live
                product.tags = tags
                product.language = language
            # save new form
            else:
                product = Product(name=name, description=description, price=price, unit=unit, live=live, tags=tags, language=language)
            if product.put():
                return redirect('/admin/shop/products/')
        return self.get(**kwargs)
        
    @cached_property
    def form(self):
        """Form instance as cached_property"""
        return ProductForm(self.request)
开发者ID:frankk00,项目名称:gae-shop,代码行数:58,代码来源:handlers.py


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