Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#11624 closed (fixed)

`render_to_kmz` can't handle non-ascii data

Reported by: jbronn Owned by: jbronn
Component: GIS Version: dev
Severity: Keywords: gis kmz render_to_kmz
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

So, say you are using the world application from the GeoDjango tutorial (source here), and you set up the following view:

from django.contrib.gis.shortcuts import render_to_kmz
from world.models import WorldBorders

def kmz(request):
    # getting only the Åland Islands, non-ascii character in the name
    qs = WorldBorders.objects.filter(id=142).kml()
    return render_to_kmz('gis/kml/placemarks.kml',
                         { 'places' : qs})

When trying to visit this view, one gets a UnicodeEncodeError instead of a KMZ file.

Because ZipFile objects only accept byte strings, the unicode string from render_to_kml needs to be encoded properly. I assume this should be for what the users has in settings.DEFAULT_CHARSET, and the attached patch does that -- but I want to have additional eyes look this over to make sure I'm doing it right.

Attachments (1)

render_to_kmz_encoding_fix.diff (682 bytes ) - added by jbronn 15 years ago.
Encode the KML as a bytestring using DEFAULT_CHARSET.

Download all attachments as: .zip

Change History (6)

by jbronn, 15 years ago

Encode the KML as a bytestring using DEFAULT_CHARSET.

comment:1 by Alex Gaynor, 15 years ago

Triage Stage: UnreviewedAccepted

comment:2 by jbronn, 15 years ago

Resolution: fixed
Status: newclosed

(In [11527]) Fixed #11624: render_to_kmz no longer balks on non-ASCII data.

comment:3 by jbronn, 15 years ago

(In [11575]) [1.1.X] Fixed #11624: render_to_kmz no longer balks on non-ASCII data.

Backport of r11527 from trunk.

comment:4 by palewire, 15 years ago

Thanks for doing this. Just patched it on 1.1 and found the fix is already in the trunk. You guys rock!

comment:5 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

Note: See TracTickets for help on using tickets.
Back to Top