當前位置: 首頁>>代碼示例>>Python>>正文


Python ProductForm.is_valid方法代碼示例

本文整理匯總了Python中forms.ProductForm.is_valid方法的典型用法代碼示例。如果您正苦於以下問題:Python ProductForm.is_valid方法的具體用法?Python ProductForm.is_valid怎麽用?Python ProductForm.is_valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在forms.ProductForm的用法示例。


在下文中一共展示了ProductForm.is_valid方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_price_positive

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
 def test_price_positive(self):
   f = ProductForm(self.product)
   self.assertTrue(f.is_valid())
   self.product['price'] = 0
   f = ProductForm(self.product)
   self.assertFalse(f.is_valid())
   self.product['price'] = -1
   f = ProductForm(self.product)
   self.assertFalse(f.is_valid())
   self.product['price'] = 1
開發者ID:sunyan125,項目名稱:health,代碼行數:12,代碼來源:tests.py

示例2: test_imgae_url_endwiths

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
  def test_imgae_url_endwiths(self):
    url_base = 'http://google.com/'
    oks = ('fred.gif', 'fred.jpg', 'fred.png', 'FRED.JPG', 'FRED.Jpg')
    bads = ('fred.doc', 'fred.gif/more', 'fred.gif.more')
    for endwith in oks:
      self.product['image_url'] = url_base+endwith
      f = ProductForm(self.product)
      self.assertTrue(f.is_valid(), msg='error when image_url endwith '+ endwith)

    for endwith in bads:
      self.product['image_url'] = url_base+endwith
      f = ProductForm(self.product)
      self.assertFalse(f.is_valid(), msg='error when image_url endwith '+ endwith)
      self.product['image_url'] = 'http://google.com/logo.png'
開發者ID:sunyan125,項目名稱:health,代碼行數:16,代碼來源:tests.py

示例3: new_product

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:34,代碼來源:views.py

示例4: add_edit

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:31,代碼來源:views.py

示例5: test_title_unique

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
    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,代碼行數:7,代碼來源:tests.py

示例6: test_attrs_cannot_empty

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
 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,代碼行數:9,代碼來源:tests.py

示例7: create

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
def create(request):
    if ( request.user.username=='' ):
        Uform = AnonymousForm(prefix='ano')
        Pform = ProductForm(prefix='prd')
        if request.method == 'POST':
            Pform = ProductForm(request.POST, request.FILES, prefix='prd')
            Uform = AnonymousForm(request.POST, prefix='ano')
            if Uform.is_valid() and Pform.is_valid():
                FileUploadHandler(request.FILES['image'])

                u = Uform.save()
                p = Pform.save()

                u.product_id = p.id

                u.save()

                return HttpResponseRedirect('/show/all/')
        else:
            Pform = ProductForm()
            Uform = AnonymousForm()
        args = {}
        args.update(csrf(request))
        args['Pform'] = Pform
        args['Uform'] = Uform
        return render_to_response('create_product_ano.html', args)

    else:
        if request.method == 'POST':
            form = ProductForm(request.POST, request.FILES)
            if form.is_valid():
                FileUploadHandler(request.FILES['image'])

                # u=User.objects.get(username=request.user.username)

                obj = form.save(commit=False)
                obj.user = request.user
                obj.save()
                return HttpResponseRedirect('/show/all/')
        else:
            form = ProductForm()

        args = {}
        args.update(csrf(request))
        args['form'] = form
        return render_to_response('create_product.html', args)
開發者ID:phuhv56,項目名稱:Chosinhvien,代碼行數:48,代碼來源:views.py

示例8: edit

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:11,代碼來源:views.py

示例9: new

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:13,代碼來源:views.py

示例10: product_add

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
def product_add(request):
  if request.method == 'POST':
    form = ProductForm(request.POST)
    if form.is_valid():
      p = form.save(commit=False)
      p.sn = generate_sn(prefix = 'PROD')
      p.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
  else:
    form = ProductForm()
    return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
開發者ID:suall936,項目名稱:test,代碼行數:14,代碼來源:views.py

示例11: my_products

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:14,代碼來源:views.py

示例12: admin_products

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:14,代碼來源:views.py

示例13: my_product

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
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,代碼行數:14,代碼來源:views.py

示例14: product_info

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
def product_info(request, product_slug, template_name="pdcts/poduct_edit.html"):
#    request.breadcrumbs( ( ("My Account", '/accounts/my_account/'), ("Edit Profile", request.path_info) ) )
    if request.method == 'POST':
        form = ProductForm(request.POST, request.FILES)
        if form.is_valid():
            product_profile.set(request, product_slug)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        pdct_profile = product_profile.retrieve(request, product_slug)
        form = ProductForm(instance=pdct_profile)
    page_title = 'Edit Product Information'
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
開發者ID:mwotil,項目名稱:nuaza,代碼行數:15,代碼來源:views.py

示例15: product_update

# 需要導入模塊: from forms import ProductForm [as 別名]
# 或者: from forms.ProductForm import is_valid [as 別名]
def product_update(request):
  if request.method == 'POST':
    postdata = request.POST.copy()
    try:
      c = Product.objects.get(sn=postdata.pop('sn')[0])
    except Product.DoesNotExist:
      raise Http404
    form = ProductForm(postdata, instance=c)
    if form.is_valid():
      p = form.save()
      serializer = JSONSimpleSerializer()
      return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
  else:
      return HttpResponse('Invalid request.')
開發者ID:suall936,項目名稱:test,代碼行數:16,代碼來源:views.py


注:本文中的forms.ProductForm.is_valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。