示例#1
0
def upload_file(request):
	if request.method == 'POST':
		form = UploadForm(request.POST, request.FILES)
		if form.is_valid():
			newdoc = Document(filename = request.POST['filename'],docfile = request.FILES['docfile'])
			newdoc.save(form)
			return redirect("uploads")
	else:
		form = UploadForm()
		#tambien se puede utilizar render_to_response
		#return render_to_response('upload.html', {'form': form}, context_instance = RequestContext(request))
	return render(request, 'upload.html', {'form': form})
示例#2
0
文件: views.py 项目: mwschouten/gps
def submit(request):

    print('REQUEST.FILES', request.FILES)
    print('REQUEST.FILES', request.FILES['docfile'].__dict__)
    print('REQUEST.POST', request.POST)
    name = request.FILES['docfile']._name
    # Handle file upload
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)

        print('FORM ', form)
        print('FORM IS VALID', form.is_valid())

        if form.is_valid():
            newdoc = Document(docfile = request.FILES['docfile'])
            newdoc.save()

            print ('NEWDOC ',newdoc)
            print ('NEWDOC ',newdoc.__dict__)
            print ('NEWDOC ',newdoc.docfile.__dict__)
            file_stored = 'media/' + newdoc.docfile.name
            print ('FILE STORED ',file_stored)

            ok,matched = import_xlsx(filename = request.FILES['docfile']._name,
                                     file_stored = file_stored)


            # Respond ANYWAY
            return JsonResponse({
                'ok':True,
                'id':newdoc.id,
                'name':request.FILES['docfile']._name,
                'size':request.FILES['docfile']._size,
                'match':'new'}
                )
        else:
            return JsonResponse({
                'ok':False,
                'errors':form.errors}
                )