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.
--- 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'