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


Python forms.ProductForm类代码示例

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


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

示例1: test_attrs_cannot_empty

 def test_attrs_cannot_empty(self):
     f = ProductForm({})
     self.assertFalse(f.is_valid())
     self.assertTrue(f['title'].errors)
     self.assertTrue(f['description'].errors)
     self.assertTrue(f['price'].errors)
     self.assertTrue(f['imageUrl'].errors)
开发者ID:Bazzinga,项目名称:django_rest_learn,代码行数:7,代码来源:tests.py

示例2: show_cat

def show_cat(cat_id):
    prodForm=ProductForm()
    prods = Product.query.filter_by(category = Category.query.get(cat_id)).all()
    cat = Category.query.get(cat_id)
    prodForm.category.default=cat.name
    prodForm.process()
    return render_template('shopapp/category.html',prods=prods,prodForm=prodForm,cat=cat)
开发者ID:iredkoz,项目名称:testapp,代码行数:7,代码来源:views.py

示例3: new_product

def new_product(request, pk):
    form = ProductForm()

    business_profile = get_object_or_404(BusinessProfile, pk=pk)

    if request.method == 'POST' and request.user.is_authenticated():
        form = ProductForm(request.POST)
        if form.is_valid():
            # check for duplicates
            # check_duplicates(Product, 
            #                  form.cleaned_data['name'], 
            #                  form.cleaned_data['product_size'],
            #                  business_profile)

            product = form.save()
            # attribute "business profile" to product
            product.business_profile = business_profile
            product.save()

            messages.add_message(request, messages.INFO,
                "You've created a product successfully. Please add raw materials used.")

            return redirect('product_add_raw_material', pk=pk, id=product.id) #, id=product.id)

        else:
            # TODO -> handel errors here!
            pass

    return render_to_response('dashboard/new_product.html',
        {'form': form},
        RequestContext(request)
        )
开发者ID:EmilyK,项目名称:costing-pro,代码行数:32,代码来源:views.py

示例4: add_edit

def add_edit(request, id=None):
    obj = None
    if id:
        obj = get_object_or_404(Product, pk=id)

    if request.method == "POST":
        form = ProductForm(request.POST, instance=obj)
        if form.is_valid():
            form.save()
            messages.success(request, 'Record has been saved successfully.')
            if id:
                return HttpResponseRedirect(reverse("internal:products:index"))
            return HttpResponseRedirect(".")
        else:
            messages.error(request, 'Failed to save record. Please correct the errors below.', extra_tags='danger')
    else:
        form = ProductForm(instance=obj)

    context = {
        'page_header': ("Edit Product ID: %s" % id) if id else "Add New Product",
        'page_title': ("Edit Product ID: %s" % id) if id else "Add New Product",
        'form': form
    }

    return render(
        request,
        'products/add_edit.html',
        context
    )
开发者ID:rpribadi,项目名称:GemahRipah,代码行数:29,代码来源:views.py

示例5: test_title_unique

    def test_title_unique(self):
        self.product['title'] = 'My Book Title'
        f = ProductForm(self.product)
        self.assertFalse(f.is_valid())
        self.product['title'] = 'My Another Book Title'

        
开发者ID:SpringAutumn,项目名称:Django_depotapp,代码行数:5,代码来源:tests.py

示例6: edit

def edit(request, pk):
    pd1 = get_object_or_404(Product,pk=id)
    form = ProductForm(request.POST or None, instance = pd1)

    if form.is_valid():
        form.save()
    t=get_template('ebook/forms.html')
    c=RequestContext(request,locals())
    return HttpResponse(t.render(c))
开发者ID:jerryxing98,项目名称:Tully,代码行数:9,代码来源:views.py

示例7: share

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,代码行数:9,代码来源:views.py

示例8: admin

def admin():
    form = LoginForm()
    prod = ProductForm()
    if prod.validate_on_submit():
        new = Product(name=prod.name.data, stock=prod.stock.data, image=prod.image.data, price=prod.price.data)
        db.session.add(new)
        db.session.commit()
        flash('Product Added!')
        return redirect(url_for('store'))
    return render_template('admin.html', prod=prod, form=form)
开发者ID:Gogu-Group,项目名称:GetAGrip,代码行数:10,代码来源:views.py

示例9: setUp

 def setUp(self):
   self.product = {
   'title':'My Book Title',
   'description':'yyy',
   'image_url':'http://google.com/logo.png',
   'price':1
   }
   f = ProductForm(self.product)
   f.save()
   self.product['title'] = 'My Another Book Title'
开发者ID:sunyan125,项目名称:health,代码行数:10,代码来源:tests.py

示例10: new

def new(request):
    form = ProductForm(request.POST or None)

    if request.method == "POST":
        form = ProductForm(request.POST)
        if form.is_valid():
            pd1 = form.save(created_by=request.user)
            return redirect('product_last')
    t = get_template('ebook/form.html')
    c = RequestContext(request,locals())
    return HttpResponse(t.render(c))
开发者ID:jerryxing98,项目名称:Tully,代码行数:11,代码来源:views.py

示例11: editProduct

def editProduct(prod_id):
    prodForm = ProductForm()
    prod = Product.query.get(prod_id)
    if prodForm.validate_on_submit():
        prod.name=prodForm.name.data
        prod.category = prodForm.category.data
        prod.note=prodForm.note.data
        prod.size = prodForm.size.data
        prod.unit=prodForm.unit.data
        db.session.commit()
    return redirect(url_for('shopapp.shop_main'))
开发者ID:iredkoz,项目名称:testapp,代码行数:11,代码来源:views.py

示例12: admin_products

def admin_products(request):
    if request.method == 'POST':
        form = ProductForm(request.POST, request.FILES)
        if form.is_valid():
            create_product(request)
        else:
            print form.errors
    if not request.user or not request.user.is_staff:
        return redirect('login')
    categories = ['Камеры', 'Антирадары']
    brands = ['Nikon', 'Canon', 'Fujitsu']
    return render(request, "core/admin/index.html", {"categories": categories, "brands": brands})
开发者ID:Magzhan123,项目名称:TabysKTS,代码行数:12,代码来源:views.py

示例13: newProduct

def newProduct():
    prodForm = ProductForm()
    name = prodForm.name.data
    if prodForm.validate_on_submit():
        if Product.query.filter_by(name=name).first():
            flash('Product with this name already exists!', 'alert-danger')
        else:
            prod = Product(name=name, category = prodForm.category.data, note=prodForm.note.data, size = prodForm.size.data, unit=prodForm.unit.data)
            db.session.add(prod)
            db.session.commit()
            return redirect(redirect_url())
    return redirect(url_for('shopapp.shop_main')) 
开发者ID:iredkoz,项目名称:testapp,代码行数:12,代码来源:views.py

示例14: my_product

def my_product(request, slug=None):
    product = get_object_or_404(Product, slug=slug)
    if request.method == 'POST':
        form = ProductForm(request.POST)
        if form.is_valid():
            updated_product = form.save(commit=False)
            updated_product.id = product.id
            updated_product.created = product.created
            updated_product.save()
    else:
        form = ProductForm(instance=product)
    return render(request, 'my_product.html', {'form': form, 'product': product})
开发者ID:roaldnefs,项目名称:scn-hackathon-2016,代码行数:12,代码来源:views.py

示例15: my_products

def my_products(request):
    user = request.user
    if request.method == 'POST':
        form = ProductForm(request.POST)
        if form.is_valid():
            form.save()
    else:
        form = ProductForm()
    companies = Company.objects.filter(owner=user)
    products = Product.objects.filter(company__in=companies)
    exchange_rate = get_rate_of_exchange()
    return render(request, 'my_products.html', {'products': products, 'form': form, 'exchange_rate': exchange_rate})
开发者ID:roaldnefs,项目名称:scn-hackathon-2016,代码行数:12,代码来源:views.py


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