from htsworkflow.frontend.bcmagic import models
from htsworkflow.frontend.bcmagic.utils import report_error, redirect_to_url
from htsworkflow.frontend.bcmagic.plugin import bcm_plugin_processor
+from htsworkflow.util.jsonutil import encode_json
-import json
import re
from htsworkflow.frontend.bcmagic import forms
# Try keyword mapper
else:
d = __magic_process(text)
- j = json.JSONEncoder()
- return HttpResponse(j.encode(d), 'text/plain')
+
+ return HttpResponse(encode_json(d), 'text/plain')
else:
text = None
- #return HttpResponse(json.write(request.POST.items()), 'text/plain')
+ #return HttpResponse(encode_json(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(encode_json(d), 'text/plain')
if text.split('|')[0] == 'url':
d['mode'] = 'redirect'
d['msg'] = 'Recieved text: %s' % (text)
d['mode'] = 'clear'
- j = json.JSONEncoder()
- return HttpResponse(j.encode(d), 'text/plain')
+ return HttpResponse(json_encode(d), 'text/plain')
from htsworkflow.frontend.inventory.models import Item, LongTermStorage
from htsworkflow.frontend.experiments.models import FlowCell
from htsworkflow.frontend.bcmagic.forms import BarcodeMagicForm
+from htsworkflow.util.jsonutil import encode_json
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse, HttpResponseRedirect
from django.template.loader import get_template
from django.contrib.auth.decorators import login_required
-import json
+
INVENTORY_CONTEXT_DEFAULTS = {
'app_name': 'Inventory Tracker',
d['rows'] = rows
- j = json.JSONEncoder()
- return HttpResponse(j.encode(d), content_type="application/javascript")
+ return HttpResponse(encode_json(d), content_type="application/javascript")
def index(request):
"""
--- /dev/null
+import json
+
+_ENCODER_METHOD = 1
+_WRITE_METHOD = 2
+
+JSON_METHOD = None
+
+try:
+ json.write({})
+except:
+ JSON_METHOD = _ENCODER_METHOD
+
+try:
+ json.JSONEncoder()
+except:
+ JSON_METHOD = _WRITE_METHOD
+
+assert JSON_METHOD is not None
+
+
+def encode_json(data):
+ """
+ encodes json data given whatever json module we have access to (2.6 builtin or python-json)
+ """
+ if JSON_METHOD == _ENCODER_METHOD:
+ j = json.JSONEncoder()
+ return j.encode(data)
+
+ elif JSON_METHOD == _WRITE_METHOD:
+ return json.write(data)
+
+ msg = "JSON_METHOD of value %s not supported." % (JSON_METHOD)
+ raise ValueError, msg
\ No newline at end of file