#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)
Change History (6)
by , 15 years ago
Attachment: | render_to_kmz_encoding_fix.diff added |
---|
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 15 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:3 by , 15 years ago
comment:4 by , 14 years ago
Thanks for doing this. Just patched it on 1.1 and found the fix is already in the trunk. You guys rock!
Encode the KML as a bytestring using
DEFAULT_CHARSET
.