Fixed json library stuff
authorBrandon King <kingb@caltech.edu>
Tue, 7 Jul 2009 22:55:08 +0000 (22:55 +0000)
committerBrandon King <kingb@caltech.edu>
Tue, 7 Jul 2009 22:55:08 +0000 (22:55 +0000)
samplebc/bcmagic/views.py

index 0b0a2bc19d2324cd99d37fb2e70d41bd0adcd775..9bc9a032c3b755622e4ef772c99385c5ad644496 100644 (file)
@@ -7,9 +7,13 @@ from samplebc.bcmagic import models
 from samplebc.bcmagic.utils import report_error, redirect_to_url
 from samplebc.bcmagic.plugin import bcm_plugin_processor
 
-import json
 import re
 
+try:
+    import json
+except ImportError, e:
+    import simplejson as json
+
 from samplebc.bcmagic import forms
 
 def index(request):
@@ -90,7 +94,7 @@ def magic(request):
     if text is None or text.strip() == '':
         d['mode'] = 'Error'
         d['status'] = 'Did not recieve text'
-        return HttpResponse(json.write(d), 'text/plain')
+        return HttpResponse(json.dumps(d), 'text/plain')
     
     # Did not receive bcm_mode error
     if bcm_mode is None or bcm_mode.strip() == '':
@@ -116,7 +120,7 @@ def magic(request):
     else:
         d = __magic_process(text)
         
-    return HttpResponse(json.write(d), 'text/plain')
+    return HttpResponse(json.dumps(d), 'text/plain')
 
 
 
@@ -128,11 +132,11 @@ def json_test(request):
     else:
         text = None
     
-    #return HttpResponse(json.write(request.POST.items()), 'text/plain')
+    #return HttpResponse(json.dumps(request.POST.items()), 'text/plain')
     if text is None or text.strip() == '':
         d['mode'] = 'Error'
         d['status'] = 'Did not recieve text'
-        return HttpResponse(json.write(d), 'text/plain')
+        return HttpResponse(json.dumps(d), 'text/plain')
     
     if text.split('|')[0] == 'url':
         d['mode'] = 'redirect'
@@ -141,4 +145,4 @@ def json_test(request):
         d['msg'] = 'Recieved text: %s' % (text)
         d['mode'] = 'clear'
         
-    return HttpResponse(json.write(d), 'text/plain')
+    return HttpResponse(json.dumps(d), 'text/plain')