Fixed #11624: `render_to_kmz` no longer balks on non-ASCII data.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11527 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Justin Bronn 2009-09-12 18:35:08 +00:00
parent 677ddcbb04
commit 1aef132090
2 changed files with 13 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import cStringIO, zipfile import cStringIO, zipfile
from django.conf import settings
from django.http import HttpResponse from django.http import HttpResponse
from django.template import loader from django.template import loader
@ -6,7 +7,7 @@ def compress_kml(kml):
"Returns compressed KMZ from the given KML string." "Returns compressed KMZ from the given KML string."
kmz = cStringIO.StringIO() kmz = cStringIO.StringIO()
zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED) zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED)
zf.writestr('doc.kml', kml) zf.writestr('doc.kml', kml.encode(settings.DEFAULT_CHARSET))
zf.close() zf.close()
kmz.seek(0) kmz.seek(0)
return kmz.read() return kmz.read()

View File

@ -1,6 +1,7 @@
import os, unittest import os, unittest
from django.contrib.gis.db.backend import SpatialBackend 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.tests.utils import no_mysql, no_oracle, no_postgis
from django.contrib.gis.shortcuts import render_to_kmz
from models import City from models import City
class GeoRegressionTests(unittest.TestCase): class GeoRegressionTests(unittest.TestCase):
@ -16,3 +17,13 @@ class GeoRegressionTests(unittest.TestCase):
self.assertEqual(pnt, City.objects.get(name='Pueblo').point) self.assertEqual(pnt, City.objects.get(name='Pueblo').point)
City.objects.filter(name='Pueblo').update(point=bak) City.objects.filter(name='Pueblo').update(point=bak)
self.assertEqual(bak, City.objects.get(name='Pueblo').point) 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})