Exemplo n.º 1
0
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)
Exemplo n.º 2
0
    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
        })
Exemplo n.º 3
0
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:')
        })
Exemplo n.º 4
0
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})
Exemplo n.º 5
0
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)
    )
Exemplo n.º 6
0
 def get(self, request):
     if Access.getuserstate():
         self.nickname = Access.getusernickname()
         form = DocumentForm()
         userid = Access.getuserid()
         filelist = File.objects.filter(Owner__User_Id=userid)
         return render(request, 'blog/main_page.html', {
             'nickname': self.nickname,
             'form': form,
             'filelist': filelist
         })
     else:
         return redirect('access_fail')
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})
Exemplo n.º 8
0
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:')
        })
Exemplo n.º 9
0
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})
Exemplo n.º 10
0
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))