X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifoldapi%2Fmanifoldproxy.py;h=5268f41e70e112e9a020f320dfe14f0bef2ecb6a;hb=a948414844c79472807c5e66939a912a7b990433;hp=5a095bfc9f3a03dd1d8debe3c6184841a8d608d1;hpb=6c38e861f92b75716f40ed9d8f15af824d1ec19c;p=myslice.git diff --git a/manifoldapi/manifoldproxy.py b/manifoldapi/manifoldproxy.py index 5a095bfc..5268f41e 100644 --- a/manifoldapi/manifoldproxy.py +++ b/manifoldapi/manifoldproxy.py @@ -10,9 +10,8 @@ from manifold.core.query import Query from manifold.core.result_value import ResultValue from manifoldapi import ManifoldAPI from manifoldresult import ManifoldException -from manifold.util.log import Log -from unfold.sessioncache import SessionCache +# from unfold.sessioncache import SessionCache from myslice.settings import config, logger @@ -32,20 +31,25 @@ debug_empty=False # myslice/urls.py # as well as # static/js/manifold.js -def proxy (request,format): +def proxy(request, format): + from myslice.settings import config + url = config.manifold_url() + return _proxy(url, request, format) + +def _proxy(url, request, format): """the view associated with /manifold/proxy/ with the query passed using POST""" # expecting a POST if request.method != 'POST': logger.error("MANIFOLDPROXY unexpected method {} -- exiting".format(request.method)) - return HttpResponse ({"ret":0}, mimetype="application/json") + return HttpResponse ({"ret":0}, content_type="application/json") # we only support json for now # if needed in the future we should probably cater for # format_in : how is the query encoded in POST # format_out: how to serve the results if format != 'json': logger.error("MANIFOLDPROXY unexpected format {} -- exiting".format(format)) - return HttpResponse ({"ret":0}, mimetype="application/json") + return HttpResponse ({"ret":0}, content_type="application/json") try: # translate incoming POST request into a query object #logger.debug("MANIFOLDPROXY request.POST {}".format(request.POST)) @@ -61,15 +65,18 @@ def proxy (request,format): admin_user, admin_password = config.manifold_admin_user_password() manifold_api_session_auth = {'AuthMethod': 'password', 'Username': admin_user, 'AuthString': admin_password} else: - manifold_api_session_auth = SessionCache().get_auth(request) - if not manifold_api_session_auth: - return HttpResponse (json.dumps({'code':0,'value':[]}), mimetype="application/json") + if 'manifold' in request.session: + manifold_api_session_auth = request.session['manifold']['auth'] + else: + #manifold_api_session_auth = SessionCache().get_auth(request) + #if not manifold_api_session_auth: + return HttpResponse (json.dumps({'code':0,'value':[]}), content_type="application/json") if debug_empty and manifold_query.action.lower()=='get': - return HttpResponse (json.dumps({'code':0,'value':[]}), mimetype="application/json") + return HttpResponse (json.dumps({'code':0,'value':[]}), content_type="application/json") # actually forward - manifold_api= ManifoldAPI(auth=manifold_api_session_auth) + manifold_api= ManifoldAPI(url, auth=manifold_api_session_auth) # for the benefit of the python code, manifoldAPI raises an exception if something is wrong # however in this case we want to propagate the complete manifold result to the js world @@ -101,13 +108,13 @@ def proxy (request,format): json_answer=json.dumps(result) - return HttpResponse (json_answer, mimetype="application/json") + return HttpResponse (json_answer, content_type="application/json") except Exception as e: logger.error("MANIFOLDPROXY {}".format(e)) import traceback logger.error(traceback.format_exc()) - return HttpResponse ({"ret":0}, mimetype="application/json") + return HttpResponse ({"ret":0}, content_type="application/json") #################### # see CSRF_FAILURE_VIEW in settings.py @@ -116,4 +123,4 @@ def proxy (request,format): failure_answer=[ "csrf_failure" ] def csrf_failure(request, reason=""): logger.error("CSRF failure with reason '{}'".format(reason)) - return HttpResponseForbidden (json.dumps (failure_answer), mimetype="application/json") + return HttpResponseForbidden (json.dumps (failure_answer), content_type="application/json")