109f59348189fbfb64c76210bf20161e9096fb60
[unfold.git] / engine / manifoldproxy.py
1 # this view is what the javascript talks to when it sends a query
2 # see also
3 # myslice/urls.py
4 # as well as 
5 # static/js/manifold-async.js
6
7 import json
8 # this is for django objects only
9 #from django.core import serializers
10 from django.http import HttpResponse, HttpResponseForbidden
11
12 from engine.manifoldquery import ManifoldQuery
13
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):
18     # expecting a POST
19     if request.method != 'POST':
20         print "manifoldproxy.api: unexpected method %s -- exiting"%request.method
21         return 
22     # we only support json for now
23     if format != 'json':
24         print "manifoldproxy.api: unexpected format %s -- exiting"%format
25         return
26
27     # xxx actually ask the backend here
28     # 4amine
29     # manifold_query = ManifoldQuery()
30     # manifold_query.fill_from_dict(request.POST)
31     # locate the api and/or the auth
32     # api=
33     # forward
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")
38
39 #################### 
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")