2 # this is for django objects only
3 #from django.core import serializers
4 from django.http import HttpResponse, HttpResponseForbidden
6 from manifold.manifoldquery import ManifoldQuery
7 from manifold.manifoldapi import ManifoldAPI
12 # add artificial delay in s
16 # this view is what the javascript talks to when it sends a query
20 # static/js/manifold.js
21 def proxy (request,format):
22 """the view associated with /manifold/proxy/
23 with the query passed using POST"""
26 if request.method != 'POST':
27 print "manifoldproxy.api: unexpected method %s -- exiting"%request.method
29 # we only support json for now
30 # if needed in the future we should probably cater for
31 # format_in : how is the query encoded in POST
32 # format_out: how to serve the results
34 print "manifoldproxy.api: unexpected format %s -- exiting"%format
37 # translate incoming POST request into a query object
38 if debug: print 'manifoldproxy.proxy: request.POST',request.POST
39 manifold_query = ManifoldQuery()
40 manifold_query.fill_from_dict(request.POST)
41 # retrieve session for request
42 manifold_api_session_auth = request.session['manifold']['auth']
44 manifold_api= ManifoldAPI(auth=manifold_api_session_auth)
45 if debug: print 'manifoldproxy.proxy: sending to backend', manifold_query
46 answer=manifold_api.send_manifold_query (manifold_query)
49 time.sleep(debug_spin)
50 # return json-encoded answer
51 return HttpResponse (json.dumps(answer), mimetype="application/json")
57 # see CSRF_FAILURE_VIEW in settings.py
58 # the purpose of redefining this was to display the failure reason somehow
59 # this however turns out disappointing/not very informative
60 failure_answer=[ "csrf_failure" ]
61 def csrf_failure(request, reason=""):
62 print "CSRF failure with reason '%s'"%reason
63 return HttpResponseForbidden (json.dumps (failure_answer), mimetype="application/json")