[FIX] rollback default conversion of js Object to py.object (not py.dict) and add...
authorXavier Morel <xmo@openerp.com>
Mon, 3 Dec 2012 12:23:12 +0000 (13:23 +0100)
committerXavier Morel <xmo@openerp.com>
Mon, 3 Dec 2012 12:23:12 +0000 (13:23 +0100)
* Accesses in contexts & domains are object derefs, so using dicts was
  dumb

* But objects still need to round-trip through in case of e.g. o2m
  commands in contexts, so py.object needs a toJSON (or a special
  object kind needs to be added, specifically for round-tripping
  objects through)

bzr revid: xmo@openerp.com-20121203122312-gc499mujf4l0nuz7

addons/web/static/lib/py.js/lib/py.js

index f36cfd6..4ef92b4 100644 (file)
@@ -393,7 +393,13 @@ var py = {};
 
         switch(val.constructor) {
         case Object:
-            return py.dict.fromJSON(val);
+            var out = py.PY_call(py.object);
+            for(var k in val) {
+                if (val.hasOwnProperty(k)) {
+                    out[k] = val[k];
+                }
+            }
+            return out;
         case Array:
             return py.list.fromJSON(val);
         }
@@ -756,7 +762,14 @@ var py = {};
 
         // Conversion
         toJSON: function () {
-            throw new Error(this.constructor.name + ' can not be converted to JSON');
+            var out = {};
+            for(var k in this) {
+                if (this.hasOwnProperty(k) && !/^__/.test(k)) {
+                    var val = this[k];
+                    out[k] = val.toJSON ? val.toJSON() : val;
+                }
+            }
+            return out;
         }
     });
     var NoneType = py.type('NoneType', null, {