本文整理汇总了Python中forms.ItemForm.is_valid方法的典型用法代码示例。如果您正苦于以下问题:Python ItemForm.is_valid方法的具体用法?Python ItemForm.is_valid怎么用?Python ItemForm.is_valid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.ItemForm
的用法示例。
在下文中一共展示了ItemForm.is_valid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createItem
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def createItem(request):
if request.POST:
form = ItemForm(request.POST, request.FILES)
if form.is_valid():
# do not save yet, and add in default owners_id
obj = form.save(commit=False)
# add in the creator's id
obj.owners = request.user
# add item status
obj.status = "Not Sold"
# save data
obj.save()
return HttpResponseRedirect("/web/main/")
else:
form = ItemForm()
args = {}
args.update(csrf(request))
args["form"] = form
args["notifications"] = Notifications.objects.filter(requestedTo=request.user, state="Pending")
args["notifications_count"] = args["notifications"].count()
args["transactions"] = Notifications.objects.filter(requestedFrom=request.user).order_by("item", "-bid")
args["transactions_count"] = args["transactions"].count()
args["online_user"] = request.user
return render_to_response("createItem.html", args)
示例2: create_item
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def create_item(request):
"""
@param request:
@param id:
@return: JSON for account for added Inventory Item
"""
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
for query in request.GET:
setattr(item, query, request.GET[query])
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': InventoryAccountSerializer(item.account).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
form.hide_field(request)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})
示例3: post_item
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def post_item(request):
if request.method == 'POST':
form = ItemForm(request.POST, request.FILES)
if form.is_valid():
m_tags = form.cleaned_data['item_tags']
m = Item(
name=form.cleaned_data['item_name'],
# type=form.cleaned_data['item_type'],
# item_image=request.FILES['item_image'],
image_first = form.cleaned_data['image_first'],
image_second= form.cleaned_data['image_second'],
image_third= form.cleaned_data['image_third'],
looking_for = True if 'True' == form.cleaned_data['item_sellOrLookFor'] else False,
category = form.cleaned_data['item_category'],
#price=form.cleaned_data['item_price'],
negotiable=form.cleaned_data['item_negotiable'],
owner=request.user,
description=form.cleaned_data['item_description']
)
m.save()
print "item has been saved with item_id "+str(m.pk)
print m_tags
m.tags.add(*m_tags)
# return my_items(request)
return HttpResponseRedirect('/')
else:
form = ItemForm()
return render_to_response('post_item.html', {'form': form, 'user': request.user}, context_instance=RequestContext(request))
示例4: item_form
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_form(request, id=None):
if id:
item = get_object_or_404(Item, id=id, company=request.company)
scenario = 'Update'
else:
item = Item(purchase_account=Account.objects.get(name='Purchase', company=request.company),
sales_account=Account.objects.get(name='Sales', company=request.company),
purchase_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company),
sales_tax_scheme=TaxScheme.objects.get(name='No Tax', company=request.company))
scenario = 'Create'
if request.POST:
form = ItemForm(data=request.POST, instance=item, company=request.company)
if form.is_valid():
item = form.save(commit=False)
item.company = request.company
item.save()
if request.is_ajax():
return render(request, 'callback.html', {'obj': ItemSerializer(item).data})
return redirect('/inventory/items/')
else:
form = ItemForm(instance=item, company=request.company)
if request.is_ajax():
base_template = 'modal.html'
else:
base_template = 'dashboard.html'
return render(request, 'item_form.html', {
'scenario': scenario,
'form': form,
'base_template': base_template,
})
示例5: item_edit
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_edit(request, item_id, response_format='html'):
"Item edit page"
item = get_object_or_404(Item, pk=item_id)
if not request.user.profile.has_permission(item, mode="w"):
return user_denied(request, message="You don't have write access to this Item",
response_format=response_format)
if request.POST:
if 'cancel' not in request.POST:
form = ItemForm(request.user.profile, item.item_type, request.POST,
files=request.FILES, instance=item)
if form.is_valid():
item = form.save(request)
return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
else:
return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
else:
form = ItemForm(
request.user.profile, item.item_type, instance=item)
context = _get_default_context(request)
context.update({'item': item,
'form': form})
return render_to_response('infrastructure/item_edit', context,
context_instance=RequestContext(request), response_format=response_format)
示例6: item_add_typed
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_add_typed(request, type_id, response_format='html'):
"Item add with preselected type"
item_type = get_object_or_404(ItemType, pk=type_id)
if not request.user.profile.has_permission(item_type, mode='x'):
return user_denied(request, message="You don't have access to create " + unicode(item_type),
response_format=response_format)
if request.POST:
if 'cancel' not in request.POST:
form = ItemForm(
request.user.profile, item_type, request.POST, files=request.FILES)
if form.is_valid():
item = form.save(request)
return HttpResponseRedirect(reverse('infrastructure_item_view', args=[item.id]))
else:
return HttpResponseRedirect(reverse('infrastructure_index'))
else:
form = ItemForm(request.user.profile, item_type)
context = _get_default_context(request)
context.update({'item_type': item_type,
'form': form})
return render_to_response('infrastructure/item_add_typed', context,
context_instance=RequestContext(request), response_format=response_format)
示例7: item_add_edit
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_add_edit(request, id=None):
item = get_object_or_404(Item, pk=id) if id else None
if request.method == "POST":
form = ItemForm(request.POST, instance=item)
if form.is_valid():
item = form.save()
# Let them know it was saved properly!
messages.success(request, "Successfully saved item %d x %s." % (item.quantity, item.sku))
# If they ask to add again, give them to this page
if request.POST.get("add_and_add", None):
return HttpResponseRedirect(reverse("item_add"))
# Else return them to home page
return HttpResponseRedirect(reverse("home"))
else:
# Let them know there is an error
messages.error(request, "There was an error.")
else:
form = ItemForm(instance=item)
return render(request, "inventory/item_add_edit.html", {"item_form": form, "item": item})
示例8: item_add
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_add(request):
if request.method == 'POST':
form = ItemForm(request, request.POST, request.FILES, prefix="item")
if form.is_valid():
item = form.save(commit=False)
item.shop = request.shop
item.save()
item.update_latest_item()
for img in request.FILES.getlist('file'):
image = ImageItem()
image.item = item
image.image.save(img.name,img)
request.flash['message'] = unicode(_("Item successfully added."))
request.flash['severity'] = "success"
return HttpResponseRedirect(reverse('inventory_items'))
else:
form = ItemForm(request, prefix="item")
form_category = MarketCategoryForm(prefix="category")
form_sub_category = MarketSubCategoryForm(request, prefix="sub_category")
form_session = AuctionSessionForm(prefix="session")
sessions = AuctionSession.objects.filter(shop = request.shop)
return render_to_response('store_admin/inventory/item_add.html',
{'form': form,
'form_category': form_category,
'form_sub_category': form_sub_category,
'form_session': form_session,
'sessions': sessions,
},
RequestContext(request))
示例9: edit_item
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def edit_item(request, item_id, cat_id):
message = ""
item = Item.objects.get(ref=item_id, category__id=cat_id)
FieldSet = inlineformset_factory(Item, Field, form=FieldForm, fields=('key','value','modified'), can_delete=False, extra=0)
if request.method == 'POST':
item_form = ItemForm(request.POST, instance=item)
form = FieldSet(request.POST, instance = item)
if item_form.is_valid() and form.is_valid():
item_form.save()
form.save()
# Re-make the form with the item from the database so
# that `modified` is set if it was changed
item = Item.objects.get(ref=item_id, category__id=cat_id)
form = FieldSet(instance=item)
item_form = ItemForm(instance=item)
message = "Item successfully saved."
if item.verified and item.category.source_file_type and item.category.collection:
if item.fields.filter(key="name").exists():
name = item.fields.get(key="name").value
else:
name = item.ref
document = docserver_create_document(item.category.collection.collectionid,
item.ref,
name)
docserver_upload_and_save_file(document.id,
item.category.source_file_type.id,
ContentFile(item.to_json()))
message += " SourceFile uploaded."
else:
item_form = ItemForm(instance=item)
form = FieldSet(instance = item)
return render(request, 'kvedit/edit.html', {'item_form':item_form, 'form': form, 'item': item, "message": message})
示例10: item_detail
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_detail(request, item_code):
from forms import ItemForm
item = get_object_or_404(Item, code=item_code)
if request.method == "POST":
item_form = ItemForm(instance=item, data=request.POST)
if item_form.is_valid():
item = item_form.save()
return redirect(item)
else:
item_form = ItemForm(instance=item)
payload = {"item": item, "item_form": item_form}
return _render("warehouse/item/detail.html", payload, request)
示例11: post
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def post(self, vendor_name):
# TODO: should be editing existing item if the name of item is identical with existing one
# upload thumb
# resize thumb using google.appengine.api.images
data = ItemForm(data=self.request.POST)
if data.is_valid():
item = data.save(commit=False)
item.photo = self.get_photo()
vendor = get1_by_property(Vendor, "name", vendor_name)
vendor.items.append(item.put())
vendor.put()
self.redirect("/v/%s/item/list" % vendor_name)
else:
self.redirect("/v/%s/item/entry" % vendor_name)
示例12: create_stories
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def create_stories(request):
if request.POST:
for f in request.FILES.getlist('i_path'):
print request.FILES
form = ItemForm(request.POST, {'i_path': f})
if form.is_valid():
form.save()
return HttpRespondeRedirect('/complete')
else:
form = ItemForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render(request,"create_stories.html",args)
示例13: item_create
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def item_create(request):
if request.method == 'POST':
form = ItemForm(request.POST)
if form.is_valid():
obj = form.save(commit=False)
obj.user = request.user
obj.save()
return redirect('index')
else:
form = ItemForm()
data = {
'form': form,
}
return render_to_response('new.html', data,
context_instance=RequestContext(request))
示例14: create_item
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def create_item(request):
if request.method == 'POST':
item_form = ItemForm(request.POST,prefix='item_form')
item_content_forms = []
for lang in LANGUAGES:
item_content_forms.append({
'form':ItemContentForm(request.POST,prefix='item_content' + lang[0]),
'lang':lang[0]
})
if item_form.is_valid():
valid = False
for item_content_form in item_content_forms:
valid = item_content_form['form'].is_valid()
if not valid:
break
if valid:
item = item_form.save(commit=False)
if 'item_form_avatar' in request.FILES:
avatar_img_name = handle_uploaded_file(request.FILES['item_form_avatar'])
item.avatar_img_name = avatar_img_name
item.save()
for item_content_form in item_content_forms:
item_content = item_content_form['form'].save(commit=False)
item_content.lang = item_content_form['lang']
item_content.item = item
item_content.save()
return redirect('newinlib:administration:items_list')
else:
item_form = ItemForm(prefix="item_form")
item_content_forms = []
for lang in LANGUAGES:
item_content_forms.append({
'form':ItemContentForm(prefix='item_content' + lang[0]),
'lang':lang[0]
})
return render(request, 'newinlib/administration/create_item.html', {
'item_form': item_form,
'item_content_forms': item_content_forms,
})
示例15: add
# 需要导入模块: from forms import ItemForm [as 别名]
# 或者: from forms.ItemForm import is_valid [as 别名]
def add(request):
"""Display the 'add an item' form & save the item if validation passed"""
if request.method == 'POST':
form = ItemForm(request.POST.copy())
if form.is_valid():
item = form.save(commit=False)
item.user = request.user
item.save()
return HttpResponseRedirect("/todo/")
else:
form = ItemForm()
return render_to_response("todo/item.html", {
'form' : form,
},context_instance=RequestContext(request))