Django

Code

Ticket #6746 (closed: fixed)

Opened 4 months ago

Last modified 4 months ago

`GoogleMap` does not use `mark_safe`.

Reported by: bemclaugh@gmail.com Assigned to: jbronn
Milestone: Component: GIS
Version: gis Keywords: gis google GoogleMap
Cc: Triage Stage: Accepted
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Working with the example in contrib/gis/maps/google/init.py.

HTML does not render correctly, for example: <script> renders as: &lt;script&gt;

Using mark_safe in the view:

from django.utils.safestring import mark_safe
from django.contrib.gis.maps.google import *
from django.contrib.gis.shortcuts import *

def test(request):
    return mark_safe(render_to_response('base.html', {'google' : GoogleMap(key="blah")}))

produces a traceback:

Traceback (most recent call last):

  File "/opt/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 277, in run
    self.result = application(self.environ, self.start_response)

  File "/opt/local/lib/python2.5/site-packages/django/core/servers/basehttp.py", line 631, in __call__
    return self.application(environ, start_response)

  File "/opt/local/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 209, in __call__
    response = middleware_method(request, response)

  File "/opt/local/lib/python2.5/site-packages/django/middleware/common.py", line 90, in process_response
    if response.status_code == 404:

AttributeError: 'SafeString' object has no attribute 'status_code'

Attachments

Change History

03/10/08 04:29:29 changed by derelm

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to invalid.
  • needs_tests changed.
  • needs_docs changed.

Hi,

the traceback is generated by django-core because you're returning a string (SafeString?) instead of a HttpResponse-object. Just add a HttpResponse around mark_safe and you should be fine.

Closing this as invalid.

03/10/08 07:32:30 changed by jbronn

  • keywords set to gis google GoogleMap.
  • status changed from closed to reopened.
  • resolution deleted.
  • stage changed from Unreviewed to Accepted.

While the submitter's syntax is incorrect with respect to returning a HttpResponse object, there is an underlying problem -- HTML code produced by the GoogleMaps object is not marked as safe. Thus, when used in templates it is escaped (and thus the GoogleMaps XHTML and JavaScript will not work). Confirmed as a bug, and working on a fix.

03/10/08 07:32:50 changed by jbronn

  • owner changed from nobody to jbronn.
  • status changed from reopened to new.

03/10/08 15:33:53 changed by jbronn

  • status changed from new to assigned.
  • summary changed from mark_safe produces traceback with GoogleMap object to `GoogleMap` does not use `mark_safe`..

03/10/08 15:45:51 changed by jbronn

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [7213]) gis: Fixed #6746 by marking safe GoogleMap internal XHTML/JavaScript; added support for GPolygon and GPolyline overlays via the polygons and polylines keywords; the zoom keyword may now take a geometry for automatic zoom level determination; *.pyc files are now ignored in django.contrib.gis modules.


Add/Change #6746 (`GoogleMap` does not use `mark_safe`.)




Change Properties
Action