src/ldt/ldt/ldt_utils/middleware/swfupload.py
author cavaliet
Wed, 09 Oct 2013 10:14:55 +0200
changeset 1240 a9d953866a50
parent 323 f85caa66acf4
permissions -rw-r--r--
Added tag V01.51.05 for changeset 150a76f0f05c

"""This middleware takes the session identifier in a POST message and adds it to the cookies instead.

This is necessary because SWFUpload won't send proper cookies back; instead, all the cookies are
added to the form that gets POST-ed back to us.
"""

from django.conf import settings
from django.core.urlresolvers import reverse

class SWFUploadMiddleware(object):

    def process_request(self, request):
        if (request.method == 'POST') and (request.path == reverse('ldt.ldt_utils.views.content.upload')) and (settings.SESSION_COOKIE_NAME in request.POST):
            request.COOKIES[settings.SESSION_COOKIE_NAME] = request.POST[settings.SESSION_COOKIE_NAME] 
        
        if request.POST.has_key('csrfmiddlewaretoken'):           
            request.COOKIES['csrftoken'] = request.POST['csrfmiddlewaretoken']