本文整理汇总了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
示例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'
示例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)
)
示例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
)
示例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'
示例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)
示例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)
示例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))
示例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))
示例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))
示例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})
示例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})
示例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})
示例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))
示例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.')