Ejemplo n.º 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'))
Ejemplo n.º 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')