Permalink
Browse files

Encoding widgets works again.

  • Loading branch information...
ralphbean committed Mar 21, 2012
1 parent fb7c06b commit 07fb3c94b2eb9b52066bb47c883e57041df6847a
Showing with 14 additions and 1 deletion.
  1. +13 −0 tests/test_js.py
  2. +1 −1 tw2/core/js.py
@@ -29,3 +29,16 @@ def test_jsonified_js_function(self):
}
json = self.encode(obj)
eq_(json, '{"f": $.awesome}')
def test_encoding_widget_id(self):
from tw2.core import Widget
w = Widget("foo")
f = js_callback(js_function('jQuery')(w).click(js_symbol('onClick')))
args = {'onLoad': f}
json = self.encode(args)
eq_(json, '{"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}')
json = self.encode({'args':args})
eq_(json, '{"args": {"onLoad": function(){jQuery(\\"foo\\").click(onClick)}}}')
@@ -46,7 +46,7 @@ def __init__(self, *args, **kw):
def default(self, obj):
if isinstance(obj, self.pass_through):
return self.mark_for_escape(obj)
elif hasattr(obj, '_id'):
elif hasattr(obj, 'id'):
return str(obj.id)
return super(TWEncoder, self).default(obj)

0 comments on commit 07fb3c9

Please sign in to comment.