From 2a8d78c88ccdbdffdad39e41539068bb8fc32fe5 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Wed, 4 Apr 2012 13:46:47 +0200 Subject: [PATCH] [UP] py.js for Object and Array converters to py types bzr revid: xmo@openerp.com-20120404114647-t81pw90940canfwg --- addons/web/static/lib/py.js/.hg_archival.txt | 4 ++-- addons/web/static/lib/py.js/lib/py.js | 22 ++++++++++++++++++-- addons/web/static/lib/py.js/test/test.js | 11 +++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/addons/web/static/lib/py.js/.hg_archival.txt b/addons/web/static/lib/py.js/.hg_archival.txt index f5355e28a12..35e98c8501d 100644 --- a/addons/web/static/lib/py.js/.hg_archival.txt +++ b/addons/web/static/lib/py.js/.hg_archival.txt @@ -1,5 +1,5 @@ repo: 076b192d0d8ab2b92d1dbcfa3da055382f30eaea -node: 5adb2d9c89e53a6445e3799f9c4dc9110458c149 +node: 1758bfec1ec1dcff95dcc4c72269cc0e3d000afd branch: default latesttag: 0.5 -latesttagdistance: 9 +latesttagdistance: 11 diff --git a/addons/web/static/lib/py.js/lib/py.js b/addons/web/static/lib/py.js/lib/py.js index 3c0b13d0717..a8c952679af 100644 --- a/addons/web/static/lib/py.js/lib/py.js +++ b/addons/web/static/lib/py.js/lib/py.js @@ -384,6 +384,21 @@ var py = {}; return new py.def(val); } + switch(val.constructor) { + case Object: + var o = new py.object(); + for (var prop in val) { + if (val.hasOwnProperty(prop)) { + o[prop] = val[prop]; + } + } + return o; + case Array: + var a = new py.list(); + a.values = val; + return a; + } + throw new Error("Could not convert " + val + " to a pyval"); } // Builtins @@ -448,7 +463,7 @@ var py = {}; __getattribute__: function (name) { if (name in this) { var val = this[name]; - if ('__get__' in val) { + if (typeof val === 'object' && '__get__' in val) { // TODO: second argument should be class return val.__get__(this); } @@ -627,6 +642,9 @@ var py = {}; } return py.False; }, + __getitem__: function (index) { + return PY_ensurepy(this.values[index.toJSON()]); + }, toJSON: function () { var out = []; for (var i=0; i