Opened 6 years ago

Closed 5 years ago

Last modified 3 years ago

#11624 closed (fixed)

`render_to_kmz` can't handle non-ascii data

Reported by: jbronn Owned by: jbronn
Component: GIS Version: master
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: UI/UX:

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 6 years ago.
Encode the KML as a bytestring using DEFAULT_CHARSET.

Download all attachments as: .zip

Change History (6)

Changed 6 years ago by jbronn

Encode the KML as a bytestring using DEFAULT_CHARSET.

comment:1 Changed 6 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 5 years ago by jbronn

  • Resolution set to fixed
  • Status changed from new to closed

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

comment:3 Changed 5 years ago by jbronn

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

Backport of r11527 from trunk.

comment:4 Changed 5 years ago by palewire

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

comment:5 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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