コード例 #1
0
    def process_response(self, request, response):
        # since the middleware is a most generic way of handling with the request/response process, let's check
        # if the response is a SimpleTemplateResponse instance first
        if request.is_ajax() and isinstance(response, SimpleTemplateResponse)\
                and request.META.has_key('HTTP_X_LOAD_BLOCKS'):
            
            block_list = request.META['HTTP_X_LOAD_BLOCKS'].split(',')
            result = loader.render_template_blocks(response.template, block_list, response.context)

            return HttpResponse(dumps(result), mimetype="application/json")
コード例 #2
0
    def _inner(request, *args, **kwargs):
        response = func(request, *args, **kwargs)

        if request.is_ajax() and request.META.has_key("HTTP_X_LOAD_BLOCKS"):
            if not isinstance(response, SimpleTemplateResponse):
                raise Exception("The response must be an instance of TemplateResponse.")

            block_list = request.META["HTTP_X_LOAD_BLOCKS"].split(",")
            result = loader.render_template_blocks(response.template_name, block_list, response.context_data)

            return HttpResponse(dumps(result), mimetype="application/json")

        return response