Use offset_linkid instead of offset to scan >1000 entities.
this is a first-cut. It works in all the ways I could make earlier
versions fail. It passes link_id as URL parameters. It also has a new
class LinkCreator which makes the main body of getListContents even easier
to write.
I wasn't sure if link_id's could have non alphanumeric characters; if so, they
need to be URL encoded/decoded.
I also need to go and remove any mention of raw offsets now, because we don't
use them.
I believe I've talked about this approach with a few of you and it sounded
reasonable. Feel free to roll-back/fix/amend/comment-for-me-to-fix. This is
my first big-logic-change to Melange.
Patch by: Dan Bentley
import re
from django.utils.text import compress_string
from django.utils.cache import patch_vary_headers
re_accepts_gzip = re.compile(r'\bgzip\b')
class GZipMiddleware(object):
"""
This middleware compresses content if the browser allows gzip compression.
It sets the Vary header accordingly, so that caches will base their storage
on the Accept-Encoding header.
"""
def process_response(self, request, response):
# It's not worth compressing non-OK or really short responses.
if response.status_code != 200 or len(response.content) < 200:
return response
patch_vary_headers(response, ('Accept-Encoding',))
# Avoid gzipping if we've already got a content-encoding.
if response.has_header('Content-Encoding'):
return response
# Older versions of IE have issues with gzipped pages containing either
# Javascript and PDF.
if "msie" in request.META.get('HTTP_USER_AGENT', '').lower():
ctype = response.get('Content-Type', '').lower()
if "javascript" in ctype or ctype == "application/pdf":
return response
ae = request.META.get('HTTP_ACCEPT_ENCODING', '')
if not re_accepts_gzip.search(ae):
return response
response.content = compress_string(response.content)
response['Content-Encoding'] = 'gzip'
response['Content-Length'] = str(len(response.content))
return response