def post(self, request): if request.POST.get("file_upload") is not None: form = DocumentForm(request.POST, request.FILES) if form.is_valid(): file_name = request.POST.get("file_name") self.bucket_put_file(file_name) elif request.POST.get("file_delete") is not None: file_name = request.POST.get("file_name") self.bucket_delete_file(file_name) elif request.POST.get("file_download") is not None: file_name = request.POST.get("file_name") self.bucket_download_file(file_name) elif request.POST.get("create_directory") is not None: directory_name = request.POST.get("create_directory") self.file_save(directory_name) elif request.POST.get("delete_directory") is not None: directory_name = request.POST.get("delete_directory") self.file_delete(directory_name) form = DocumentForm() return render(request, 'blog/main_page.html', { 'nickname': self.nickname, 'form': form, 'filelist': filelist })
def my_view(request): print( f"Great! You're using Python 3.6+. If you fail here, use the right version." ) message = 'Upload as many files as you want!' # Handle file upload if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): newdoc = Documents(docfile=request.FILES['docfile']) author = request.user published_date = timezone.now() newdoc.save() # Redirect to the document list after POST return redirect('my-view') else: message = 'The form is not valid. Fix the following error:' else: form = DocumentForm() # An empty, unbound form # Load documents for the list page documents = Documents.objects.all() # Render list page with the documents and the form context = {'documents': documents, 'form': form, 'message': message} return render(request, 'blog/post_list.html', context)
def Statements_Upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): df = pd.read_excel(request.FILES['document']) teste = df['sharpe'][1] chemalle = df['sharpe'][2] #df2 = df['sharpe'][2] #writer = pd.ExcelWriter('teste.xlsx') #filehandle = df.to_excel(writer) #writer.save() return render(request, 'index.html', { 'chemalle': chemalle, 'teste': teste }) # return excel.make_response(pe.get_sheet(file_name='teste.xlsx'), "csv",file_name='forecast_2018') else: form = Statements() return render( request, 'statements.html', { 'form': form, 'title': 'Excel file upload and download example', 'header': ('Please choose any excel file ' + 'from your cloned repository:') })
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() return redirect('form_upload') else: form = DocumentForm() return render(request, 'blog/model_form_upload.html', {'form': form})
def upload_file(request): global rate global file form = DocumentForm(request.POST, request.FILES) if form.is_valid(): rate = form.cleaned_data['description'] file = form.cleaned_data['document'].name if form.is_valid(): form.save() return HttpResponseRedirect(reverse('main_chart')) else: form = DocumentForm() return render(request, 'blog/add_data.html', {'form': form}, context_instance=RequestContext(request))
def post_new(request): if request.method == "POST": form = DocumentForm(request.POST, request.FILES) if form.is_valid(): post_new = form.save(commit=False) post_new.author = request.user post_new.save() return redirect('my-view') else: form = DocumentForm() return render(request, 'blog/post_edit.html', {'form': form})
def findMissing(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): form.save() result = searchImage(request.FILES['document'].name, form.cleaned_data['name']) request.session['result'] = result return HttpResponseRedirect(reverse('blog:myresults')) else: form = DocumentForm() return render(request, 'blog/findMissing.html', {'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() # Redirect to the document list after POST return HttpResponseRedirect(reverse('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( 'myapp/list.html', {'documents': documents, 'form': form}, context_instance=RequestContext(request) )
def model_form_upload(request): if request.method == 'POST': form = DocumentForm(request.POST, request.FILES) if form.is_valid(): df = pd.read_excel(request.FILES['document']) writer = pd.ExcelWriter('teste.xlsx') filehandle = df.to_excel(writer) writer.save() return excel.make_response(pe.get_sheet(file_name='teste.xlsx'), "csv", file_name='forecast_2018') else: form = DocumentForm() return render( request, 'blog/model_form_upload.html', { 'form': form, 'title': 'Excel file upload and download example', 'header': ('Please choose any excel file ' + 'from your cloned repository:') })