maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 1/4] Modifications around JSON handling


From: Pierre Mauduit
Subject: [Maposmatic-dev] [PATCH 1/4] Modifications around JSON handling
Date: Sun, 20 Dec 2009 15:05:09 +0100

From: Pierre Mauduit <address@hidden(none)>

Should work on python JSON modules, fixed generation of JSON output
(without templates)
---
 www/maposmatic/views.py                       |   14 ++++++++----
 www/templates/maposmatic/query_nominatim.html |   28 -------------------------
 2 files changed, 9 insertions(+), 33 deletions(-)
 delete mode 100644 www/templates/maposmatic/query_nominatim.html

diff --git a/www/maposmatic/views.py b/www/maposmatic/views.py
index 739a785..fe87726 100644
--- a/www/maposmatic/views.py
+++ b/www/maposmatic/views.py
@@ -28,7 +28,7 @@ from django.forms.util import ErrorList
 from django.forms import CharField, ChoiceField, FloatField, RadioSelect, \
                          ModelForm, ValidationError
 from django.shortcuts import get_object_or_404, render_to_response
-from django.http import HttpResponseRedirect, HttpResponseBadRequest
+from django.http import HttpResponseRedirect, HttpResponseBadRequest, 
HttpResponse
 from django.utils.translation import ugettext_lazy as _
 from django.template import RequestContext
 
@@ -47,7 +47,13 @@ from ocitysmap.coords import BoundingBox as OCMBoundingBox
 from urllib import urlencode
 import urllib2
 from xml.etree.ElementTree import parse as XMLTree
-import json
+try:
+    from json import dumps as json_encode
+except ImportError:
+    try:
+        from cjson import encode as json_encode
+    except ImportError:
+        from json import write as json_encode
 
 
 # Test if a given city has its administrative boundaries inside the
@@ -302,9 +308,7 @@ def query_nominatim(request, format, squery):
         contents = []
 
     if format == "json":
-        return render_to_response('maposmatic/query_nominatim.html',
-                                  { 'contents': json.dumps(contents) },
-                                  context_instance=RequestContext(request))
+        return HttpResponse(content = json_encode(contents), mimetype = 
'text/json')
 
 def about(request):
     return render_to_response('maposmatic/about.html',
diff --git a/www/templates/maposmatic/query_nominatim.html 
b/www/templates/maposmatic/query_nominatim.html
deleted file mode 100644
index 2566b88..0000000
--- a/www/templates/maposmatic/query_nominatim.html
+++ /dev/null
@@ -1,28 +0,0 @@
-{% comment %}
- coding: utf-8
-
- maposmatic, the web front-end of the MapOSMatic city map generation system
- Copyright (C) 2009  David Decotigny
- Copyright (C) 2009  Frédéric Lehobey
- Copyright (C) 2009  David Mentré
- Copyright (C) 2009  Maxime Petazzoni
- Copyright (C) 2009  Thomas Petazzoni
- Copyright (C) 2009  Gaël Utard
-
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- GNU Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-{% endcomment %}
-
-{% block page %}
-{{ contents }}
-{% endblock %}
-- 
1.6.5.7





reply via email to

[Prev in Thread] Current Thread [Next in Thread]