Пример #1
0
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))
Пример #2
0
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.')