Skip to content

Commit

Permalink
Make sure JSON output are byte strings.
Browse files Browse the repository at this point in the history
This works around https://code.djangoproject.com/ticket/24240 which
otherwise dies when trying to cope with a StreamingHttpResponse
containing unicode strings.
  • Loading branch information
dracos committed Jan 30, 2015
1 parent ae4e58b commit c3ff8fb
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mapit/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from django.shortcuts import get_object_or_404 as orig_get_object_or_404
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.utils.six.moves import map
from django.utils.encoding import smart_str

from django.core.serializers.json import DjangoJSONEncoder
# Assuming at least python 2.6, in Django < 1.6, the above class is either a
Expand Down Expand Up @@ -60,6 +62,7 @@ def output_json(out, code=200):
indent = 4
encoder = GEOS_JSONEncoder(ensure_ascii=False, indent=indent)
content = encoder.iterencode(out)
content = map(smart_str, content) # Workaround Django bug #24240

types = {
400: http.HttpResponseBadRequest,
Expand Down

0 comments on commit c3ff8fb

Please sign in to comment.