Exemple #1
0
    def post(self, request):

        # Handle file upload
        newfile = None
        if request.method == 'POST':
            print request.POST
            form = DocumentForm(request.POST, request.FILES)
            post = Post.objects.get(id = request.POST['post_id'])
            if form.is_valid() and post:
                newfile = PostFileUpload(file = request.FILES['datafile'], post = post, name=str(request.FILES['datafile']))
                newfile.save()
        return HttpResponseRedirect(reverse('dashboard'))
Exemple #2
0
def angular_post(request):
    print request.POST
    newfile = None
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        post = Post.objects.get(id = request.POST['post_id'])
        if form.is_valid() and post:
            newfile = PostFileUpload(file = request.FILES['datafile'], post = post, name=str(request.FILES['datafile']))
            newfile.save()

    if newfile:
        filedata = FileSerializer(newfile)
        return HttpResponse(JSONRenderer().render(filedata.data), content_type='application/json')
    else:
        return HttpResponse({}, content_type='application/json')
Exemple #3
0
def model_form_upload(request):
    if request.method == 'POST':
        form = DocumentForm(request.POST, request.FILES)
        if form.is_valid():
            form.save()
            return redirect('logout')
    else:
        form = DocumentForm()
    return render(request, 'templates/model_form_upload.html', {'form': form})