* 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
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);
}
// 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, {