1 # this view is what the javascript talks to when it sends a query
5 # static/js/manifold-async.js
8 # this is for django objects only
9 #from django.core import serializers
10 from django.http import HttpResponse, HttpResponseForbidden
12 from engine.manifoldquery import ManifoldQuery
14 # xxx should probably cater for
15 # format_in : how is the query encoded in POST
16 # format_out: how to serve the results
17 def api (request,format):
19 if request.method != 'POST':
20 print "manifoldproxy.api: unexpected method %s -- exiting"%request.method
22 # we only support json for now
24 print "manifoldproxy.api: unexpected format %s -- exiting"%format
27 # xxx actually ask the backend here
29 # manifold_query = ManifoldQuery()
30 # manifold_query.fill_from_dict(request.POST)
31 # locate the api and/or the auth
34 # answer=api.send_manifold_query (manifold_query)
35 hard_wired_answer = [ {'slice_hrn':'a.b.c'}, {'slice_hrn':'ple.inria.foo' } ]
36 answer=hard_wired_answer
37 return HttpResponse (json.dumps(answer), mimetype="application/json")
40 # to enable : see CSRF_FAILURE_VIEW in settings.py
41 # probably we want to elaborate this one a little in real life
42 # at least we can display the reason in the django output (although this turns out disappointing)
43 failure_answer=[ "csrf_failure" ]
44 def csrf_failure(request, reason=""):
45 print "CSRF failure with reason '%s'"%reason
46 return HttpResponseForbidden (json.dumps (failure_answer), mimetype="application/json")