def upload(request): # Handle file upload if request.user.is_authenticated() == False: return HttpResponseRedirect('/accounts/login') print(request.user.is_authenticated()) if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): some_var = request.POST.getlist('checks[]') print some_var newdoc = Document(docfile=request.FILES['docfile'], videoname=request.POST['videoname'], channel=some_var[0]) newdoc.save() clip = VideoFileClip('media/'+str(newdoc.docfile)) clip.save_frame('media/frame'+str(newdoc.id)+'.png', t=2) newVideo = VideoQueue(videoID=newdoc.id, clipduration=clip.duration, clipurl='frame'+str(newdoc.id)+'.png') newVideo.save() # Redirect to the document list after POST return HttpResponseRedirect('/myapp/index?videoid='+str(newVideo.id)) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render( request, 'list.html', {'documents': documents, 'form': form} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(user=request.POST['user'], docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # _get_token() # Load documents for the list page documents = {} documents_db = Document.objects.all() for document in documents_db: if documents.has_key(document.user): documents[document.user].append(document) else: documents[document.user] = [document] # Render list page with the documents and the form return render(request, 'list.html', {'documents': documents, 'form': form})
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() url=newdoc.docfile.url obj = Classification() name = obj.imageClassification(newdoc.docfile.path) Predicted_image_name=name[0] # Redirect to the document list after POST return render(request,'abc.html',{"image_path" : url,"object_name" : Predicted_image_name}) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response( 'list.html', {'documents': documents, 'form': form}, context_instance=RequestContext(request) )
def list(request): if request.method == 'GET': return HttpResponseRedirect("/home/") # return HttpResponse('This page shows a list of most recent posts.') # pass # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() runScript() # Redirect to the document list after POST return HttpResponseRedirect("../home/") else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('home.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): imglist=[] namelist=[] if request.method=='POST': form=DocumentForm(request.POST,request.FILES) if 'file' in request.FILES: image=request.FILES['file'] imglist.append(image) if 'file1' in request.FILES: image=request.FILES['file1'] imglist.append(image) for image in imglist: u=Document() u.docfile=image namelist.append(u.docfile) u.save() path1='D:/87/media/'+str(namelist[0]) path2='D:/87/media/'+str(namelist[1]) path=imgtest(path1,path2) return render(request, 'list.html', {'form': form, 'path':path}) #return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() return render( request, 'list.html', {'form': form} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) files = request.FILES.getlist('docfile') # files = form.cleaned_data['docfile'] for newdoc in files: if form.is_valid(): # newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render( request, 'list.html', {'documents': documents, 'form': form} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() url = newdoc.docfile.url request.session['file_url'] = url # Redirect to the document list after POST return HttpResponseRedirect( reverse('myproject.myapp.views.email_url')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('myapp/list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('myproject.myapp.views.list')) else: form = DocumentForm() # empty, unbound form # Load documents for the list page documents = Document.objects.all() api_res = [] # for f in documents: # api_res.append(faceApi(f.docfile.url)) # Render list page with the documents and the form return render_to_response('myapp/list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() #pass to opencv BASE_PATH = '/home/apon/Ongoing/SDL/myproject/media/' folder = 'documents/' uploaded_filename = request.FILES['docfile'].name full_filename = BASE_PATH + folder + uploaded_filename print(full_filename) #global images = opencv.ProcessImage(full_filename) # Redirect to the document list after POST #return HttpResponseRedirect(reverse('myproject.myapp.views.list')) return HttpResponseRedirect(reverse('myproject.myapp.views.show')) #return render(request, 'show.html') else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): picture = form.save() print(picture.docfile) file = os.path.join(settings.MEDIA_ROOT, picture.docfile.name) result = {} print ('Extracting features from image %s' % file) name = file.split('/')[-1].lower() result[name] = extract_features(file) picture.features = pickle.dumps(result) picture.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render( request, 'list.html', {'documents': documents, 'form': form} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() text = pytesseract.image_to_string(Image.open(newdoc.docfile), lang='eng', config='digits') #writing data in data.doc file handle = open('data.doc', 'w+') handle.write(text) handle.close() #writing data in data.txt file textFile = open('data.txt', 'w+') textFile.write(text) textFile.close() ll = [] with open('data.txt', 'r') as readFile: rr = readFile.readline() ll.append(rr) readFile.close() f = open('data.doc', 'r') for x in f: ll.append(x) file_content = ll f.close() #writing data in data.csv file with open('data.csv', 'w') as csvFile: writer = csv.writer(csvFile) writer.writerow(ll) csvFile.close() context = {'file_content': file_content} # Redirect to the document list after POST return render(request, 'showText.html', context) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() my_document = None for document in documents: my_document = document # Render list page with the documents and the form return render(request, 'list.html', { 'documents': my_document, 'form': form })
def upload_files(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile = request.FILES['docfile'],user=request.user) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('myproject.myapp.views.list')) else: form = DocumentForm() # Load documents for the list page # d1=Document() # documents = d1.get_my_files(request.user) documents = Document.objects.filter(user=request.user) # shared_doc = Document.objects.filter(user=request.user) # shared_doc=Document.objects.filter(event__to_user=request.user) # sharing.objects.filter(shared_user=request.user) #filter(shared_file= ,shared_user= ) # Render list page with the documents and the form return render_to_response( 'list.html', {'documents': documents, 'form': form, 'username':request.user }, context_instance=RequestContext(request) )
def gif(request, guid_id): user = get_object_or_404(User, pk=guid_id) # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): orig_file = request.FILES['docfile'] orig_image = Image.open(orig_file) point = pointillizeStack(image=orig_image, reduce_factor=2, border=0, queue=True) point.resize(0, 550) point.plot('balanced') multipliers = [ 5, 4.5, 4, 3.5, 3, 2.6, 2.3, 2, 1.75, 1.5, 1.25, 1.1, 1, 1 ] multipliers.reverse() point.build_multipliers(multipliers, reverse=True) # point.save_gif('temp/' + guid_id + '_pointqueue.gif', 0.1) new_gif_IO = io.BytesIO() point.save_gif(new_gif_IO, 0.1) new_file = InMemoryUploadedFile( new_gif_IO, u"docfile", # change this? (orig_file.name.split('.')[0] + ' pointillized.gif'), 'image/gif', None, None) newdoc = user.document_set.create(docfile=new_file) newdoc.save() origdoc = user.document_set.create(docfile=orig_file) origdoc.save() # os.remove('temp/' + guid_id + '_pointqueue.gif') # Redirect to the document upload page after POST return HttpResponseRedirect( reverse('gif', kwargs={'guid_id': user.pk})) else: form = DocumentForm() # A empty, unbound form # Load documents for the upload page all_documents = user.document_set.order_by("-id") documents = [] for document in all_documents: if (document.docfile.name[-16:] == 'pointillized.gif'): documents.append(document) # Render upload page with the documents and the form return render(request, 'upload_to_gif.html', { 'documents': documents, 'form': form, 'guid_id': user.pk })
def upload(request, template='upload.html'): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) files = request.FILES.getlist('file') if form.is_valid(): for f in files: handle_uploaded_file(f) return HttpResponse('upload success') else: form = DocumentForm() return render(request, 'upload.html', {'form': form})
def list(request): # Handle file upload if request.method == 'POST': print "reset logIn to empty" print "HERE IS THE POST METHOD" form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() print("Retrive the uploaded file") dirTwoLevelUp = os.path.abspath( os.path.join(os.path.dirname(__file__), '../..', 'media/documents')) addSlashToFile = '/' + request.FILES['docfile'].name uploadedFileAbsPath = os.path.join(dirTwoLevelUp, request.FILES['docfile'].name) print("uploadedFileAbsPath : ") print(uploadedFileAbsPath) print("fileFormatSelection: ") print(request.POST['fileFormatSelection']) if (request.POST['fileFormatSelection'] == 'M_V_1'): ValidationIndex = 1 else: ValidationIndex = 3 print("Start the validation process") validateMarginFile.validateMarginFileProcess( uploadedFileAbsPath, ValidationIndex, logInfo, logError) # validateMarginFile.validateMarginFileProcess("/Users/mifang/Documents/Expedia/Project/tutorial/djangoTutorial/dq-djang-python-validation-webapp/myproject/myproject/myapp/resource/DataFile/sample3.0.csv",3,logInfo) print("Start to remove the file from the folder") try: os.remove(uploadedFileAbsPath) except: print("Failed to remove the file from cloud") print "HERE IS THE LogInfo before reverse to log" print logInfo # Redirect to the document list after POST return HttpResponseRedirect(reverse('log')) else: print "HERE ISTHE ELSE CONDTION" form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render(request, 'list.html', {'documents': documents, 'form': form})
def upload(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): my_file = Paths("/home/fernando/Desktop/myproject/media/samples/" + request.FILES['docfile'].name) if my_file.is_file(): os.remove("/home/fernando/Desktop/myproject/media/samples/" + request.FILES['docfile'].name) # remove duplicates newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() my_file = '/home/fernando/Desktop/myproject/media/samples/' + request.FILES[ 'docfile'].name pathtofile = my_file.encode('ascii', 'ignore') subprocess.call( '/home/fernando/Desktop/myproject/myproject/myapp/submitsample.sh ' + pathtofile, shell=True) time.sleep(5) latest_file_sha = max([ os.path.join('/home/fernando/.cuckoo/storage/binaries', d) for d in os.listdir('/home/fernando/.cuckoo/storage/binaries') ], key=os.path.getmtime) latest_file_sha = os.path.basename(latest_file_sha) latest_dir_analisys = os.path.basename( os.readlink('/home/fernando/.cuckoo/storage/analyses/latest')) filename = request.FILES['docfile'].name dirpath = '/home/fernando/.cuckoo/storage/analyses/' + str( (int(latest_dir_analisys) + 1)) + '/' newinfo = Path(namefile=filename, idsha256=latest_file_sha, pathto=dirpath) # Ok newinfo.save() print newinfo.idsha256 # analisysinfo = Path.objects.create(namefile=filename,idsha256=latest_file_sha,pathto=dirpath) return render( request, 'submited.html', { 'latest_file_sha': latest_file_sha, 'dirpath': dirpath, 'filename': filename }) # Redirect to the document list after POST # return HttpResponseRedirect(reverse('upload')) else: form = DocumentForm() # A empty, unbound form # Render list page with the documents and the form return render(request, 'upload.html', {'form': form})
def upload(request, guid_id): user = get_object_or_404(User, pk=guid_id) # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): orig_file = request.FILES['docfile'] orig_image = Image.open(orig_file) point = pointillize(image=orig_image, reduce_factor=2) # point.plotRecPoints(n=40, multiplier=1, fill=False) # point.plotRandomPointsComplexity(n=2e4, constant=0.01, power=1.3) point.resize(ratio=0, min_size=2200) setting = request.POST['setting'] point.plot(setting) new_stringIO = io.BytesIO() point.out.convert('RGB').save( new_stringIO, orig_file.content_type.split('/')[-1].upper()) new_file = InMemoryUploadedFile( new_stringIO, u"docfile", # change this? (orig_file.name.split('.')[0] + ' ' + setting + ' pointillized.jpg'), orig_file.content_type, None, None) newdoc = user.document_set.create(docfile=new_file) newdoc.save() origdoc = user.document_set.create(docfile=orig_file) origdoc.save() # Redirect to the document upload page after POST return HttpResponseRedirect( reverse('upload', kwargs={'guid_id': user.pk})) else: form = DocumentForm() # A empty, unbound form # Load documents for the upload page all_documents = user.document_set.order_by("-id") documents = [] for document in all_documents: if document.docfile.name[-16:] == 'pointillized.jpg': documents.append(document) # Render upload page with the documents and the form return render(request, 'upload.html', { 'documents': documents, 'form': form, 'guid_id': user.pk })
def uploadtest(request): # Handle file upload if request.method == 'POST': docform = DocumentForm(request.POST, request.FILES) if docform.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) filename = docform.cleaned_data['docfile'].name.split('.')[0] fileformat = docform.cleaned_data['docfile'].name.split('.')[-1] name = docform.cleaned_data['your_name'] my = filename.split('_')[0] vp = filename.split('_')[1] code = filename.split('_')[2] phase = filename.split('_')[3] ftime = filename.split('_')[-1] fname = filename.replace(" ","_") localtime = timeNorm(ftime) # localtime = time.strftime('%Y-%m-%d',time.localtime(time.time())) if fileformat == 'xlsx': pythoncom.CoInitialize() newdoc.save() summaryTable = 'D:/DjangoWeb/myproject/media/DYNOTable.csv' fpath = 'D:/DjangoWeb/myproject/media/documents/' + fname csvfile = file(summaryTable,'ab+') writer = csv.writer(csvfile) writer.writerow([name,filename,vp,code,phase,localtime,my]) csvfile.close() convertExcel(fpath) # else: # raise forms.ValidationError("gaga") # Redirect to the document list after POST else: docform = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render( request, 'upload.html', {'documents': documents, 'form': docform} )
def list(request): if request.method == 'GET': return HttpResponseRedirect("/home/") # return HttpResponse('This page shows a list of most recent posts.') # pass # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): # Manage Sessions lock.acquire() sId = '0' try: sId = open("sessionId.txt", 'rb').read() except Exception as e: print e try: sId = str((int(sId)) + 1) except Exception as e: sId = '1' print e open("sessionId.txt", 'wb').write(sId) request.session['id'] = sId # lock.release() newdoc = Document(docfile=request.FILES['docfile']) fname = request.FILES['docfile'].name request.session['filename'] = fname newdoc.save() runScript(request) lock.release() # Redirect to the document list after POST return HttpResponseRedirect("../home/") else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('home.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def filename(request): pair ={} results = [] # Handle file upload if request.method == 'POST': form = ImageForm(request.POST, request.FILES) if form.is_valid(): #newdoc = Document(docfile=request.FILES['docfile']) #newdoc.save() #picture = Document.objects.get(name = picture_name) documents = Document.objects.all() documents_dict = {} features = {} names = [] for i in documents: name = i.docfile.name.split('/')[-1].lower() names.append(name) features[name] = pickle.loads(i.features)[(i.docfile.name).lower()] documents_dict[name] = i #names.append(request.FILES['docfile'].name) file = os.path.join(settings.MEDIA_ROOT, request.FILES['docfile'].name) print(file) files = [os.path.join(settings.MEDIA_ROOT, p) for p in names] #print ('Extracting features from image %s' % file) #name = file.split('/')[-1].lower() #features[name] = extract_features(file) #print(features) #print(len(files)) ma = Matcher(features) print ('Query image ==========================================') names, match = ma.match(file) print ('ЭТО documents_dict') print (documents_dict) pair = zip(names,match) list_pair = sorted(pair, key=lambda x: x[-1]) for n, w in list_pair: documents_dict[n].weight = w results.append(documents_dict[n]) print('Wheight %s' % (1-w)) print ('Result images ========================================') #print (names) #print (match) for m in range(len(files)): print ('Match %s' % (1-match[m])) else: form = DocumentForm() # A empty, unbound form # Render list page with the documents and the form return render( request, 'filename.html', {'form': form, 'documents': results} )
def home(request): form = DocumentForm() documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): global i # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() i += 1 # import ipdb;ipdb.set_trace() d = Document.objects.get(id=i) #print d.docfile k = pytesseract.image_to_string(Image.open(d.docfile)) #print k handle = open('data.txt', 'a+') handle.write(k) handle.close() txt_file = r"data.txt" csv_file = r'mycsv.csv' in_txt = csv.reader(open(txt_file, "rb"), delimiter=' ') out_csv = csv.writer(open(csv_file, 'wb')) out_csv.writerows(in_txt) # Redirect to the document list after POST return HttpResponseRedirect(reverse('myproject.myapp.views.list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render_to_response('list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() dict = {'names': newdoc.docfile.name, 'urls': newdoc.docfile.url} return HttpResponse(json.dumps(dict), mimetype="application/json") else: form = DocumentForm() # A empty, unbound form documents = Document.objects.all() return render_to_response('myapp/list.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): if '_googleapiclient' in request.POST: print("Google Api Client Test") print(googleapiremote("a")) elif '_upload' in request.POST: newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render(request, 'list.html', {'documents': documents, 'form': form})
def list(request): tags = Gallery.objects.filter(username=request.user) tagArray = [] while (tags): tagArray.append(tags.first().tag) tags = tags.exclude(tag=tags.first().tag) #choices = Document.objects.order_by().values('tag').distinct() # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): tagSpace = slugify(request.POST.get('tag')) if Gallery.objects.filter(username=request.user,tag=tagSpace).exists(): newdoc = Document(docfile=request.FILES['docfile'],gallery=Gallery.objects.filter(username=request.user,tag=tagSpace).first()) newdoc.save() else: newGallery = Gallery(username=request.user,tag=tagSpace,thumb=request.FILES['docfile']) newGallery.save() newdoc = Document(docfile=request.FILES['docfile'],gallery=newGallery) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page galleries = Gallery.objects.all() # Render list page with the documents and the form return render( request, 'list.html', {'form': form,'galleries':galleries,'tags':tagArray} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() global renders renders = net.run('./' + newdoc.docfile.url) # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form # Render list page with the documents and the form return render( request, 'list.html', {'renders': renders, 'form': form} )
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() profile = Profile() print("X", profile.photo.avatar) # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render(request, 'list.html', { 'documents': documents, 'form': form, 'profile': profile })
def list(request): # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('list')) else: form = DocumentForm() # A empty, unbound form #Viewing the graph # for document in documents: # EmotionAnalysis.printgraph(document.docfile.name) # Load documents for the list page documents = Document.objects.all() # Render list page with the documents and the form return render(request, 'list.html', {'documents': documents, 'form': form})
def home(request): import os # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Document(docfile=request.FILES['docfile']) newdoc.save() # Redirect to the document list after POST return HttpResponseRedirect(reverse('myproject.myapp.views.home')) else: form = DocumentForm() # A empty, unbound form # Load documents for the list page documents = Document.objects.all() for document in documents: document.docfile.documentName = os.path.basename(document.docfile.name) # Render list page with the documents and the form return render_to_response('home.html', { 'documents': documents, 'form': form }, context_instance=RequestContext(request))