Fwd: FlotWidget - tw.jquery 0.9.4 and tg2b7 - empty

26 views
Skip to first unread message

percious

unread,
Mar 23, 2009, 1:55:46 PM3/23/09
to toscawidge...@googlegroups.com
This is actually a pretty major change to the core. Have you tried
the tests after this change? I have forwarded this message to the tw
ml:

http://groups.google.com/group/toscawidgets-discuss

cheers.
-chris

---------- Forwarded message ----------
From: Andrew Basson <andrew.bas...@gmail.com>
Date: Mar 20, 8:45 pm
Subject: FlotWidget - tw.jquery 0.9.4 and tg2b7 - empty
To: TurboGears Trunk


Hi,

Ok, I hacked and got a chart...

2009/3/21 Andrew Basson <andrew.bas...@gmail.com>:

> Hi,

>>http://paste.turbogears.org/paste/39329

> With further investigation and editing the output of the rendered
> template as a static page and trying to get that to work...

> It seems that tw.core.js is escaping the id of the widget and this is
> breaking tw.jquery.FlotWidget

> Here is a snippet from tw.core.js that shows the escaping behaviour of
> the id selector as per the paste above.

Ok, so I hacked __get_js_repr on _js_call and put in a replace as per
below.

class _js_call(object):
    __slots__ = ('__name', '__call_list', '__args', '__called')

    def __init__(self, name, call_list, args=None, called=False):
        self.__name = name
        self.__args = args
        call_list.append(self)
        self.__call_list = call_list
        self.__called = called

    def __getattr__(self, name):
        return self.__class__(name, self.__call_list)

    def __call__(self, *args):
        self.__args = args
        self.__called = True
        return self

    def __get_js_repr(self):
        if self.__called:
            args = self.__args
            return '%s(%s)' % (self.__name, ', '.join(imap(encode,
args)).replace('\\',''))
        else:
            return self.__name

Don't know what else will break, but for now I'm happy to fall into
bed knowing I can finally produce a chart.

Cheers, Andrew.

srlindemann

unread,
Mar 24, 2009, 9:28:01 AM3/24/09
to ToscaWidgets-discuss
This is the same problem I have encountered this week and recently
sent to the list. I don't think that Andrew's solution is the correct
one, in the general case. I looked at the simplejson source, and the
issue is that it runs all inputs through the encoder; in the past,
overriding _iterencode_default actually allowed you to bypass the
encoder (e.g., to directly inject js code in a string). Take a look
at r118 of encoder.py; compare the use of _iterencode_default (old) to
default (new)

http://code.google.com/p/simplejson/source/diff?spec=svn118&r=118&format=side&path=/trunk/simplejson/encoder.py

As far as I can tell, this is intentional---I don't think that Bob
Ippolito really intends arbitrary code to be injected. As a result, I
think tw.core.js needs to have a direct mechanism to bypass the
encoding. My initial sketch of the solution is to have TWEncoder
override the encode method, looking for a get_js_repr attr to bypass
encoding. E.g.,

class TWEncoder(simplejson.encoder.JSONEncoder):

def __init__(self, *args, **kw):
super(TWEncoder, self).__init__(*args, **kw)

def default(self, obj):
if hasattr(obj, '_id') and obj.id!=None:
r = simplejson.encoder.encode_basestring(obj.id)
return r
return simplejson.encoder.JSONEncoder.default(self, obj)

def encode(self, obj):
if hasattr(obj, 'get_js_repr'):
return obj.get_js_repr()
return simplejson.encoder.JSONEncoder.encode(self, obj)

Then the four classes currently in the pass_through tuple all need to
implement the method (only _js_call does it currently) to return the
correct representation. I'll probably submit a patch if I can get
around to it.

Andrew Basson

unread,
Mar 24, 2009, 3:36:21 PM3/24/09
to toscawidge...@googlegroups.com
Hi Percious and srlindemann,

2009/3/24 srlindemann <srlin...@gmail.com>:


>
> This is the same problem I have encountered this week and recently
> sent to the list.  I don't think that Andrew's solution is the correct
> one, in the general case.  I looked at the simplejson source, and the

I agree that my solution is a little drastic and way off the charts.
No pun intended :)

Thanks for the feedback.

Andrew.

srlindemann

unread,
Mar 26, 2009, 5:04:38 PM3/26/09
to ToscaWidgets-discuss
I posted a patch a few minutes ago:

http://toscawidgets.org/trac/tw/ticket/30

I'd appreciate any feedback/advice.

Thanks,

Steve

On Mar 24, 2:36 pm, Andrew Basson <andrew.bas...@gmail.com> wrote:
> Hi Percious and srlindemann,
>
> 2009/3/24 srlindemann <srlindem...@gmail.com>:

andrew...@gmail.com

unread,
Mar 30, 2009, 5:04:03 PM3/30/09
to ToscaWidgets-discuss
Hi Steve,


On Mar 26, 11:04 pm, srlindemann <srlindem...@gmail.com> wrote:
> I posted a patch a few minutes ago:
>
> http://toscawidgets.org/trac/tw/ticket/30
>
> I'd appreciate any feedback/advice.
>
I have tested js_v2.py as js.py and it looks good. The FlotWidgets
have their ID's set correctly.

Cheers, Andrew.
Reply all
Reply to author
Forward
0 new messages