Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[1.1.X] Fixed #11624: `render_to_kmz` no longer balks on non-ASCII data.

Backport of r11527 from trunk.


git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.1.X@11575 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5f68bf0182e1ca0eeb637143d468aa96c01b218b 1 parent 0c222b6
@jbronn jbronn authored
View
3  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()
View
11 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 @@ def test01_update(self):
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' : '<Point><coordinates>5.0,23.0</coordinates></Point>'
+ }]
+ kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
+
Please sign in to comment.
Something went wrong with that request. Please try again.