Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 3112563f4b
Fetching contributors…

Cannot retrieve contributors at this time

69 lines (57 sloc) 1.962 kB
import datetime
import json
except ImportError:
import simplejson as json
from django.http import HttpResponse, HttpResponseBadRequest
from django.views.decorators.http import require_POST
from matchbox.api import LocalClient
client = LocalClient('datacommons')
def _querydict_to_dict(qd):
d = {}
for k,l in qd.iterlists():
if len(l) == 1:
l = l[0]
d[str(k)] = l
return d
def _jsonize(data):
if isinstance(data, list):
return [_jsonize(i) for i in data]
for k,v in data.iteritems():
if isinstance(v, datetime.datetime):
data[k] = str(v)
return data
def entity(request, uid=None):
data = None
if request.method == 'POST':
if uid:
key = client.update(uid, **_querydict_to_dict(request.POST))
key = client.insert(_querydict_to_dict(request.POST))
except TypeError, e:
return HttpResponseBadRequest(str(e))
data = {'id':key}
elif request.method == 'GET':
if uid:
data = client.get(uid)
data = list(**_querydict_to_dict(request.GET)))
return HttpResponse(json.dumps(_jsonize(data)))
def make_merge(request):
name = request.POST.get('name')
ids = request.POST.getlist('id')
source = request.POST.get('source')
_type = request.POST.get('type')
if not name:
return HttpResponseBadRequest('missing required parameter "name"')
if not ids or len(ids) < 2:
return HttpResponseBadRequest('must specify two or more id parameters to merge')
data = client.make_merge(name, ids, source, _type)
return HttpResponse(json.dumps(_jsonize(data)))
def commit_merge(request):
merge_record = _querydict_to_dict(request.POST)
new_id = client.commit_merge(merge_record)
return HttpResponse(json.dumps({'id':new_id}))
Jump to Line
Something went wrong with that request. Please try again.