Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
  • Loading branch information...
commit 1aef132090f5717add930e5e5da2287235b85b68 1 parent 677ddcb
Justin Bronn authored September 12, 2009
3  django/contrib/gis/shortcuts.py
... ...
@@ -1,4 +1,5 @@
1 1
 import cStringIO, zipfile
  2
+from django.conf import settings
2 3
 from django.http import HttpResponse
3 4
 from django.template import loader
4 5
 
@@ -6,7 +7,7 @@ def compress_kml(kml):
6 7
     "Returns compressed KMZ from the given KML string."
7 8
     kmz = cStringIO.StringIO()
8 9
     zf = zipfile.ZipFile(kmz, 'a', zipfile.ZIP_DEFLATED)
9  
-    zf.writestr('doc.kml', kml)
  10
+    zf.writestr('doc.kml', kml.encode(settings.DEFAULT_CHARSET))
10 11
     zf.close()
11 12
     kmz.seek(0)
12 13
     return kmz.read()
11  django/contrib/gis/tests/geoapp/test_regress.py
... ...
@@ -1,6 +1,7 @@
1 1
 import os, unittest
2 2
 from django.contrib.gis.db.backend import SpatialBackend
3 3
 from django.contrib.gis.tests.utils import no_mysql, no_oracle, no_postgis
  4
+from django.contrib.gis.shortcuts import render_to_kmz
4 5
 from models import City
5 6
 
6 7
 class GeoRegressionTests(unittest.TestCase):
@@ -16,3 +17,13 @@ def test01_update(self):
16 17
         self.assertEqual(pnt, City.objects.get(name='Pueblo').point)
17 18
         City.objects.filter(name='Pueblo').update(point=bak)
18 19
         self.assertEqual(bak, City.objects.get(name='Pueblo').point)
  20
+
  21
+    def test02_kmz(self):
  22
+        "Testing `render_to_kmz` with non-ASCII data, see #11624."
  23
+        name = '\xc3\x85land Islands'.decode('iso-8859-1')
  24
+        places = [{'name' : name,
  25
+                  'description' : name,
  26
+                  'kml' : '<Point><coordinates>5.0,23.0</coordinates></Point>'
  27
+                  }]
  28
+        kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})
  29
+

0 notes on commit 1aef132

Please sign in to comment.
Something went wrong with that request. Please try again.