本文整理汇总了Python中common.serializers.JSONSimpleSerializer类的典型用法代码示例。如果您正苦于以下问题:Python JSONSimpleSerializer类的具体用法?Python JSONSimpleSerializer怎么用?Python JSONSimpleSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了JSONSimpleSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sale_json
def sale_json(request):
serializer = JSONSimpleSerializer()
if 'sn' in request.GET:
sale = SaleOrder.objects.filter(sn = request.GET['sn'])
else:
sale = SaleOrder.objects.all()
return HttpResponse(serializer.serialize(sale, use_natural_foreign_keys=True))
示例2: customer_delete
def customer_delete(request):
if request.method == 'POST':
delete_customer = Customer.objects.get(sn=request.POST['sn'])
delete_name = unicode(delete_customer)
delete_customer.delete()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([delete_customer,]))
else:
return HttpResponse("Invalid request.")
示例3: saleItem_json
def saleItem_json(request):
"""return json of all sale_items with sn as sale.sn. For ajax"""
if request.GET['sn']:
try:
p = SaleOrder.objects.get(sn=request.GET['sn'])
except SaleOrder.DoesNotExist:
raise Http404
pi = p.saleitem_set.all().order_by("sn")
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
else:
return HttpResponse("Invalid request.")
示例4: vendor_add
def vendor_add(request):
if request.method == 'POST':
form = VendorForm(request.POST)
if form.is_valid():
p = form.save(commit=False)
p.sn = generate_sn(prefix = 'VDR')
p = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([p,], use_natural_foreign_keys=True))
else:
form = VendorForm()
return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
示例5: currencyRate_json
def currencyRate_json(request):
"""return json of all currencyRate with sn as currency.sn. For ajax"""
if request.GET['sn']:
try:
p = Currency.objects.get(sn=request.GET['sn'])
except Currency.DoesNotExist:
raise Http404
pi = p.fromRates.all().order_by("sn")
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
else:
return HttpResponse("Invalid request.")
示例6: customer_add
def customer_add(request):
if request.method == 'POST':
form = CustomerForm(request.POST)
if form.is_valid():
c = form.save(commit=False)
c.sn = generate_sn(prefix = 'CTM')
c.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([c,]))
else:
form = CustomerForm()
return render_to_response('modal/main_form.html',{'action':'Add', 'module':module, 'form': form},context_instance=RequestContext(request))
示例7: currencyRate_update
def currencyRate_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
sn = postdata.pop('sn')[0]
p = Currency.objects.get(pk=postdata['fromCurrency'][0])
pi = CurrencyRate.objects.get(fromCurrency=p, sn=sn)
form = CurrencyRateForm(postdata, instance=pi)
if form.is_valid():
pi_saved = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([pi_saved,], use_natural_foreign_keys=True))
else:
pass
示例8: product_update
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.')
示例9: vendor_update
def vendor_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
try:
c = Vendor.objects.get(sn=postdata.pop('sn')[0])
except Vendor.DoesNotExist:
raise Http404(module + ' not found')
form = VendorForm(postdata, instance=c)
if form.is_valid():
c_saved = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([c_saved,]))
else:
return HttpResponse('Invalid request.')
示例10: saleItem_update
def saleItem_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
p_pk = postdata.pop('order')[0]
sn = postdata.pop('sn')[0]
p = SaleOrder.objects.get(pk=p_pk)
pi = SaleItem.objects.get(order=p, sn=sn)
form = SaleItemForm(postdata, instance=pi)
if form.is_valid():
pi_saved = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([pi_saved,], use_natural_foreign_keys=True))
else:
pass
示例11: currency_update
def currency_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
try:
p = Currency.objects.get(sn=postdata.pop('sn')[0])
except Currency.DoesNotExist:
raise Http404(module + ' not found')
form = CurrencyForm(postdata, instance=p)
print form.errors
if form.is_valid():
p_saved = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([p_saved,]))
else:
return HttpResponse('Invalid request.')
示例12: purchase_update
def purchase_update(request):
if request.method == 'POST':
postdata = request.POST.copy()
try:
p = PurchaseOrder.objects.get(sn=postdata.pop('sn')[0])
except PurchaseOrder.DoesNotExist:
raise Http404(module + ' not found')
form = PurchaseForm(postdata, instance=p)
print form.errors
if form.is_valid():
p_saved = form.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([p_saved,],use_natural_foreign_keys=True))
else:
return HttpResponse('Invalid request.')
示例13: purchaseItem_add
def purchaseItem_add(request):
if request.method == 'POST':
postdata = request.POST.copy()
p_sn = postdata.pop('itemLinkSn')[0]
sn = postdata.pop('sn')[0]
form = Purchase_ItemForm(postdata)
if form.is_valid():
pi = form.save(commit=False)
p = PurchaseOrder.objects.get(sn=p_sn)
pi.order = p
pi.sn = Purchase_Item.objects.filter(order = p).count() + 1
pi.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
else:
return HttpResponse("Invalid request.")
示例14: currencyRate_add
def currencyRate_add(request):
if request.method == 'POST':
postdata = request.POST.copy()
# currency_pk = postdata.pop('fromCurrency')[0]
sn = postdata.pop('sn')[0]
form = CurrencyRateForm(postdata)
if form.is_valid():
pi = form.save(commit=False)
p = Currency.objects.get(pk=postdata['fromCurrency'][0])
# pi.sn = CurrencyRate.objects.filter(fromCurrency = p).count() + 1
pi.sn = p.fromRates.count() + 1
pi.save()
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize([pi,], use_natural_foreign_keys=True))
else:
return HttpResponse("Invalid request.")
示例15: currencyConvertTo_json
def currencyConvertTo_json(request):
"""return json of all currencyRate with sn specified the currency converted to. For ajax"""
if request.GET['sn']:
try:
p = Currency.objects.get(sn=request.GET['sn'])
print p
except Currency.DoesNotExist:
raise Http404
if p.code == 'AUD':
fromCurrency = Currency.objects.get(code ='CNY')
elif p.code == 'CNY':
fromCurrency = Currency.objects.get(code ='AUD')
pi = p.toRates.all().filter(fromCurrency = fromCurrency).order_by('-isDefault')
serializer = JSONSimpleSerializer()
return HttpResponse(serializer.serialize(pi, use_natural_foreign_keys=True))
else:
return HttpResponse("Invalid request.")