# -*- coding: utf-8 -*-

from django.http import HttpResponse
from updateable import settings


class UpdateableMiddleware(object):

    def process_request(self, request):
        updateable = bool(request.GET.get(settings.UPDATEABLE_GET_VARIABLE))
        hashvals = {}
        if updateable:
            ids = request.GET.getlist('ids[]')
            hashes = request.GET.getlist('hash[]')
            for id, hash in zip(ids, hashes):
                hashvals[id] = hash
        updateable_dict = {
            'updateable': updateable,
            'hashes': hashvals,
            'contents': [],
        }
        setattr(request, settings.UPDATEABLE_REQUEST_OBJECT, updateable_dict)

    def process_response(self, request, response):
        updateable_dict = getattr(request, settings.UPDATEABLE_REQUEST_OBJECT)
        if updateable_dict['updateable']:
            contents = updateable_dict['contents']
            content = ''.join(contents)
            response['Content-length'] = str(len(content))
            if getattr(response, 'streaming', False):
                response.streaming_response = (content,)
            else:
                response.content = content
        return response


@@ -1177,16 +1177,87 @@
 content%0A
+            response%5B'Cache-control'%5D = 'no-cache' # Preventing IE bug%0A
         

Fix for AJAX cache bug in IE