From: Thierry Parmentelat Date: Mon, 11 Mar 2013 08:27:12 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/myslice-django X-Git-Tag: myslice-django-0.1-1~43^2~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=9b09d9222d0311b5212eff97f2b3d7fab134a657;hp=d48845006f4fdd65c7f03782a45a785936edf8e3;p=unfold.git Merge branch 'master' of ssh://git.onelab.eu/git/myslice-django --- diff --git a/engine/manifoldapi.py b/engine/manifoldapi.py index 40b95c1d..ebb6b4a9 100644 --- a/engine/manifoldapi.py +++ b/engine/manifoldapi.py @@ -31,11 +31,9 @@ class ManifoldAPI: # 4amine : xxx def send_manifold_query (self, manifold_query): - (action,method)= (raw_query.action,raw_query.method) + (action,method)= (manifold_query.action,manifold_query.method) if action=='get': - return self.Get(method, - # need to fill in the other args here - ) + return self.proxy.Get(self.auth, method, manifold_query.filters, {}, manifold_query.fields) # xxx... elif action=='others': return None diff --git a/engine/manifoldproxy.py b/engine/manifoldproxy.py index 109f5934..a66f187a 100644 --- a/engine/manifoldproxy.py +++ b/engine/manifoldproxy.py @@ -10,6 +10,7 @@ import json from django.http import HttpResponse, HttpResponseForbidden from engine.manifoldquery import ManifoldQuery +from engine.manifoldapi import ManifoldAPI # xxx should probably cater for # format_in : how is the query encoded in POST @@ -23,17 +24,13 @@ def api (request,format): if format != 'json': print "manifoldproxy.api: unexpected format %s -- exiting"%format return - # xxx actually ask the backend here - # 4amine - # manifold_query = ManifoldQuery() - # manifold_query.fill_from_dict(request.POST) - # locate the api and/or the auth - # api= + manifold_query = ManifoldQuery() + manifold_query.fill_from_dict(request.POST) + manifold_api_session_auth = request.session['manifold']['auth'] + manifold_api= ManifoldAPI(auth=manifold_api_session_auth) # forward - # answer=api.send_manifold_query (manifold_query) - hard_wired_answer = [ {'slice_hrn':'a.b.c'}, {'slice_hrn':'ple.inria.foo' } ] - answer=hard_wired_answer + answer=manifold_api.send_manifold_query (manifold_query) return HttpResponse (json.dumps(answer), mimetype="application/json") #################### diff --git a/engine/manifoldquery.py b/engine/manifoldquery.py index e48c94d6..8e25ed9e 100644 --- a/engine/manifoldquery.py +++ b/engine/manifoldquery.py @@ -53,7 +53,13 @@ class ManifoldQuery: # to see an example just look at the server's output # incoming POST def fill_from_dict (self, d): - # mandatory... - self.action=d['action'] - self.method=d['method'] - # + for key in d.keys(): + for arg in ['action', 'method', 'filters', 'fields', 'timestamp', 'params']: + if arg in key: + # dirty hack around fields; fields must be a list + if arg == 'fields': + setattr(self, arg, [d[key]]) + else: + setattr(self, arg, d[key]) + break + diff --git a/engine/static/js/query.js b/engine/static/js/query.js index 1dd4aa7f..4a64bdde 100644 --- a/engine/static/js/query.js +++ b/engine/static/js/query.js @@ -1,4 +1,4 @@ -function Query(action, method, ts, filter, params, fields, unique, uuid, aq, sq) +function Query(action, method, timestamp, filters, params, fields, unique, uuid, aq, sq) { // get, update, delete, create var action; @@ -7,10 +7,10 @@ function Query(action, method, ts, filter, params, fields, unique, uuid, aq, sq) var method; // timestamp, now, latest(cache) : date of the results queried - var ts; + var timestamp; // key(field),op(=<>),value - var filter; + var filters; // todo var params; @@ -44,29 +44,29 @@ INSERT INTO method VALUES(field=value) return jQuery.extend(true, q, this); } this.add_filter = function(key, op, value) { - this.filter.push(new Array(key, op, value)); + this.filters.push(new Array(key, op, value)); } this.update_filter = function(key, op, value) { // Need to be improved... // remove all occurrences of key if operation is not defined if(!op){ - this.filter = jQuery.grep(this.filter, function(val, i) { + this.filters = jQuery.grep(this.filters, function(val, i) { return val[0] != key; }); - // Else remove the key+op filter + // Else remove the key+op filters }else{ - this.filter = jQuery.grep(this.filter, function(val, i) {return (val[0] != key || val[1] != op);}); + this.filters = jQuery.grep(this.filters, function(val, i) {return (val[0] != key || val[1] != op);}); } - this.filter.push(new Array(key, op, value)); + this.filters.push(new Array(key, op, value)); } this.remove_filter = function (key,op,value){ // if operator is null then remove all occurences of this key if(!op){ - this.filter = jQuery.grep(this.filter, function(val, i) { + this.filters = jQuery.grep(this.filters, function(val, i) { return val[0] != key; }); }else{ - this.filter = jQuery.grep(this.filter, function(val, i) {return (val[0] != key || val[1] != op);}); + this.filters = jQuery.grep(this.filters, function(val, i) {return (val[0] != key || val[1] != op);}); } } // FIXME These functions computing diff's between queries are meant to be shared @@ -85,8 +85,8 @@ INSERT INTO method VALUES(field=value) // FIXME Modify filter to filters this.diff_filter = function (otherQuery) { - var f1 = this.filter; - var f2 = otherQuery.filter; + var f1 = this.filters; + var f2 = otherQuery.filters; /* added elements are the ones in f2 not in f1 */ var added = jQuery.grep(f2, function (x) { return !arrayInArray(x, f1)}); @@ -96,7 +96,7 @@ INSERT INTO method VALUES(field=value) return {'added':added, 'removed':removed}; } this.to_hash = function() { - return {'action': this.action, 'method': this.method, 'ts': this.ts, 'filters': this.filter, 'params': this.params, 'fields': this.fields}; + return {'action': this.action, 'method': this.method, 'timestamp': this.timestamp, 'filters': this.filters, 'params': this.params, 'fields': this.fields}; } this.analyze_subqueries = function() { @@ -105,7 +105,7 @@ INSERT INTO method VALUES(field=value) q.uuid = this.uuid; q.action = this.action; q.method = this.method; - q.ts = this.ts; + q.timestamp = this.timestamp; /* Filters */ jQuery.each(this.filters, function(i, filter) { @@ -120,7 +120,7 @@ INSERT INTO method VALUES(field=value) q.subqueries[this.method] = new Query(); q.subqueries[this.method].action = this.action; q.subqueries[this.method].method = this.method; - q.subqueries[this.method].ts = this.ts; + q.subqueries[this.method].timestamp = this.timestamp; } q.subqueries[this.method].filters.push(Array(field, op, v)); } else { @@ -138,7 +138,7 @@ INSERT INTO method VALUES(field=value) q.subqueries[this.method] = new Query(); q.subqueries[this.method].action = this.action; q.subqueries[this.method].method = this.method; - q.subqueries[this.method].ts = this.ts; + q.subqueries[this.method].timestamp = this.timestamp; } q.subqueries[this.method].params[field] = value; } else { @@ -156,7 +156,7 @@ INSERT INTO method VALUES(field=value) q.subqueries[this.method] = new Query(); q.subqueries[this.method].action = this.action; q.subqueries[this.method].method = this.method; - q.subqueries[this.method].ts = this.ts; + q.subqueries[this.method].timestamp = this.timestamp; } q.subqueries[this.method].fields.push(field); } else { @@ -169,8 +169,8 @@ INSERT INTO method VALUES(field=value) /* constructor */ this.action = action; this.method = method; - this.ts = ts; - this.filter = filter; + this.timestamp = timestamp; + this.filters = filters; this.params = params; this.fields = fields; this.unique = unique;