Argument to_json added to json function in Base view.
authorDaniel Hans <Daniel.M.Hans@gmail.com>
Mon, 17 Aug 2009 18:43:23 +0200
changeset 2779 db04432cb99a
parent 2778 44bb0e89cc1b
child 2780 0362fb7e3b3c
Argument to_json added to json function in Base view. Its value (which should be a boolean) determines if the data should be converted to a JSON object. Therefore if someone has already a JSON string and wants to return it in a HTTP response, he or she may set to_json=False and the object will not be converted.
app/soc/views/models/base.py
--- a/app/soc/views/models/base.py	Mon Aug 17 14:01:13 2009 +0200
+++ b/app/soc/views/models/base.py	Mon Aug 17 18:43:23 2009 +0200
@@ -18,6 +18,7 @@
 """
 
 __authors__ = [
+  '"Daniel Hans" <daniel.m.hans@gmail.com>',
   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
   '"Lennard de Rijk" <ljvderijk@gmail.com>',
   '"Pawel Solyga" <pawel.solyga@gmail.com>',
@@ -724,15 +725,19 @@
 
     return self.json(request, data)
 
-  def json(self, request, data):
+  def json(self, request, data, to_json=True):
     """Returns data as a json object.
+
+    Args:
+      request: the standard Django HTTP request object
+      data: the data to be sent as a json object
+      to_json: determines if the data should be converted to a json object
     """
 
-    to_json = {
-        'data': data,
-        }
-
-    json = simplejson.dumps(to_json)
+    if to_json:
+      json = simplejson.dumps({'data': data})
+    else:
+      json = data
 
     context = {'json': json}
     template = 'soc/json.html'