diff --git a/django/contrib/gis/shortcuts.py b/django/contrib/gis/shortcuts.py index e62e2b6bc8..a6fb8927d0 100644 --- a/django/contrib/gis/shortcuts.py +++ b/django/contrib/gis/shortcuts.py @@ -1,4 +1,5 @@ import cStringIO, zipfile +from django.conf import settings from django.http import HttpResponse from django.template import loader @@ -6,7 +7,7 @@ def compress_kml(kml): "Returns compressed KMZ from the given KML string." kmz = cStringIO.StringIO() zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED) - zf.writestr('doc.kml', kml) + zf.writestr('doc.kml', kml.encode(settings.DEFAULT_CHARSET)) zf.close() kmz.seek(0) return kmz.read() diff --git a/django/contrib/gis/tests/geoapp/test_regress.py b/django/contrib/gis/tests/geoapp/test_regress.py index ef8d44d988..6eecfc8de4 100644 --- a/django/contrib/gis/tests/geoapp/test_regress.py +++ b/django/contrib/gis/tests/geoapp/test_regress.py @@ -1,6 +1,7 @@ import os, unittest from django.contrib.gis.db.backend import SpatialBackend from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis +from django.contrib.gis.shortcuts import render_to_kmz from models import City class GeoRegressionTests(unittest.TestCase): @@ -16,3 +17,13 @@ class GeoRegressionTests(unittest.TestCase): self.assertEqual(pnt, City.objects.get(name='Pueblo').point) City.objects.filter(name='Pueblo').update(point=bak) self.assertEqual(bak, City.objects.get(name='Pueblo').point) + + def test02_kmz(self): + "Testing `render_to_kmz` with non-ASCII data, see #11624." + name = '\xc3\x85land Islands'.decode('iso-8859-1') + places = [{'name' : name, + 'description' : name, + 'kml' : '5.0,23.0' + }] + kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places}) +