예제 #1
0
def purchasedoc_create_process(request,object_id):
    #raise TypeError
    purchase = get_object_or_404(Purchase, pk=object_id)
    if request.method == 'POST': # If the form has been submitted...
        
        purchasedoc_data = request.POST.copy()
        docform = PurchaseDocForm(data=purchasedoc_data,files=request.FILES,purchase=purchase)

        if docform.is_valid():
            filename = handle_uploaded_file(request.FILES['doc'])
            docform.files = filename
            docform.save()

            handle_uploaded_file_BOXNET(request,filename)
                
            return HttpResponseRedirect(ROOT_URL + 'user/purchasedocs/create/success/') # Redirect to details
        else:
            return HttpResponseRedirect(ROOT_URL + 'user/purchases/create/fail/') # Redirect to details
        
        # try backup at box.net
        
    else:
        form = ContactForm() # An unbound form

    return render_to_response('contact.html', {
        'form': form,
    })
예제 #2
0
def purchase_create_addfile(request):

    if request.method == 'POST': # If the form has been submitted...
        
        purchasedoc_data = request.POST.copy()
        docform = PurchaseDocForm(data=purchasedoc_data,files=request.FILES)

        if docform.is_valid():
            filename = handle_uploaded_file(request.FILES['doc'])
            docform.files = filename
            docform.save()

            #handle_uploaded_file_BOXNET(request,filename)
                
            return HttpResponseRedirect('success/') # Redirect to details
        else:
            return HttpResponseRedirect('fail/') # Redirect to details
        
        # try backup at box.net
        
    else:
        form = PurchaseDocForm() # An unbound form

    return render_to_response('generic_create_form.html', {'form_list':[form],
                                        'form_display_mode_table':True,
                                        'form_is_multipart':True},
             context_instance=RequestContext(request))
예제 #3
0
def purchase_create_ajax(request):
    if request.method == 'POST': # If the form has been submitted...    
        if request.is_ajax():           
            post_data = request.POST.copy()
            post_data = json.loads(post_data.keys()[0])  # need to fix that, now all inputs are as key
            
            print request.FILES
            
            purchaseRequestForm = PurchaseRequestForm(post_data['id_purchaseRequestForm'] or None)
            purchase_costForm = Purchase_costForm(post_data['id_purchase_costForm'] or None)
            purchaseDocForm = PurchaseDocForm(post_data['id_purchaseDocForm'] or None)
            #form4 = PurchaseDocForm(request.POST or None)
            
            if purchaseRequestForm.is_valid() and purchase_costForm.is_valid():
                if purchaseDocForm.is_valid():
                    filename = handle_uploaded_file(request.FILES['doc'])
                    purchaseDocForm.files = filename
            
                    purchaseDocForm_instance = purchaseDocForm.save()
                else:
                    purchaseDocForm_instance = None
                    
                purchase_cost_instance = purchase_costForm.save()
                asset_group_instance = purchaseRequestForm.save(cost=purchase_cost_instance,
                                                                person=request.user,
                                                                docs=purchaseDocForm_instance)
                


                json_ser = Serializer()
                availdata = json_ser.serialize([asset_group_instance])
                avail_json_data = JSONEncoder().encode(availdata)
                
                return HttpResponse(avail_json_data, mimetype='application/json')
                
            else:
                json_ser = Serializer()
                availdata = json_ser.serialize({'id_purchaseRequestForm':purchaseRequestForm.errors,
                                                'id_purchase_costForm':purchase_costForm.errors,
                                                'id_purchaseDocForm':purchaseDocForm.errors})
        
                avail_json_data = JSONEncoder().encode(availdata)
                return HttpResponseBadRequest(avail_json_data, mimetype='application/json',status=400)