+def _execute_query(request, query, manifold_api_session_auth):
+ manifold_api = ManifoldAPI(auth=manifold_api_session_auth)
+ print "-"*80
+ print query
+ print query.to_dict()
+ print "-"*80
+ result = manifold_api.forward(query.to_dict())
+ if result['code'] == 2:
+ # XXX only if we know it is the issue
+ del request.session['manifold']
+ # Flush django session
+ request.session.flush()
+ #raise Exception, 'Error running query: %r' % result
+
+ if result['code'] == 1:
+ print "WARNING"
+ print result['description']
+
+ # XXX Handle errors
+ #Error running query: {'origin': [0, 'XMLRPCAPI'], 'code': 2, 'description': 'No such session: No row was found for one()', 'traceback': 'Traceback (most recent call last):\n File "/usr/local/lib/python2.7/dist-packages/manifold/core/xmlrpc_api.py", line 68, in xmlrpc_forward\n user = Auth(auth).check()\n File "/usr/local/lib/python2.7/dist-packages/manifold/auth/__init__.py", line 245, in check\n return self.auth_method.check()\n File "/usr/local/lib/python2.7/dist-packages/manifold/auth/__init__.py", line 95, in check\n raise AuthenticationFailure, "No such session: %s" % e\nAuthenticationFailure: No such session: No row was found for one()\n', 'type': 2, 'ts': None, 'value': None}
+
+ return result['value']
+
+def execute_query(request, query):
+ if not 'manifold' in request.session or not 'auth' in request.session['manifold']:
+ request.session.flush()
+ raise Exception, "User not authenticated"
+ manifold_api_session_auth = request.session['manifold']['auth']
+ return _execute_query(request, query, manifold_api_session_auth)
+
+def execute_admin_query(request, query):
+ config = Config()
+ admin_user, admin_password = config.manifold_admin_user_password()
+ admin_auth = {'AuthMethod': 'password', 'Username': admin_user, 'AuthString': admin_password}
+ return _execute_query(request, query, admin_auth)