Commit 5f68bf01 authored by Justin Bronn's avatar Justin Bronn
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
parent 0c222b61
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
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()
+11 −0
Original line number Diff line number Diff line
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' : '<Point><coordinates>5.0,23.0</coordinates></Point>'
                  }]
        kmz = render_to_kmz('gis/kml/placemarks.kml', {'places' : places})