0

Hi I'm using Uploadify in one of my django applications. It works fine. But when I use the @user_passes_test decorator, uploadify is getting a Http 302 error. Only logged in users with a specific permission should be allowed to use the fileupload.

my view looks like this:

@user_passes_test(lambda u: u.has_perm('cylebrations.can_multiupload'))
def myFileHandler(request):
    if request.method == 'POST':
        for field_name in request.FILES:
            image=Image(gallery_id=gallery.id, image=request.FILES[field_name])
            image.save()
            return HttpResponse("ok", mimetype="text/plain")
    return render_to_response('gallery_upload.html', context_instance=RequestContext(request))

when I use something like following in the view instead of the decorator, I also get a 302 error.

if not request.user.has_perm('cylebrations.can_multiupload'):
    return HttpResponse("You can't upload.")

It looks like the view doesn't get the userinformation. Is there any way to pass the neccessary user information through uploadifys postData setting? How can I use uploadify with django permissions?

jarred
  • 745
  • 2
  • 8
  • 19

1 Answers1

0

Here is a forum entry, that shows how it can be done: http://www.uploadify.com/forum/#/discussion/7195/uploadify-3-0-beta-with-django/p1

It contains a link to another stackoverflow question which might be helpful too.

Community
  • 1
  • 1
Maccesch
  • 1,998
  • 1
  • 18
  • 27
  • I created a middleware and added the formData to my uploadify options. But I still get a Http404 error. – jarred Jun 02 '12 at 23:03
  • I edited my answer because I found some links. They are doing basically the same I proposed but it seems they already tested their solution – Maccesch Jun 03 '12 at 21:03