... one last thing before I shut up for today ;)

The last line, I think, should read:

return '%s(%s)' % (callback, json_encode(template_vars))

And without meaning to sound too much like a sycophant: thanks
again! :) I really do appreciate your time, effort and input in this
matter :D

Cheers,
C

On Oct 23, 2:08 pm, Christoph Zwerschke <[email protected]> wrote:
> Am 23.10.2010 01:45 schrieb [email protected]:
>
> > Also, I'm not entirely happy with the way I'm excluding the TG dict
> > keys in the render function - so if anyone wants to chip in a better
> > solution, I'd be extremely grateful ;)
>
> Yes, that's really not nice. A somewhat better solution is requesting
> the keys to be removed from tg, instead of using the hardcoded list.
>
> Also, JSONP controllers should deliver a 'text/javascript' mime type
> instead of the default 'text/html'.
>
>  > NOTE: the current implementation presupposes that you pass in the
>  > JSONP callback method in the URL parameter 'jsoncallback'. E.g.
>  >http://my.site.com/path/to/controller?jsoncallback=mycallback
>
> In addition to that, you could abuse the template_name for defining a
> default for the callback function on the server side, and add a fixed
> default in case it is not set via template name or parameter.
>
> Example: expose('jsonp:mycallbackmethod')
>
> So my improved solution looks like this:
>
> from tg import json_encode, response
> from tg.render import _get_tg_vars
>
> def render_jsonp(template_name, template_vars, **kwargs):
>      callback = (template_name
>          or kwargs.pop('callback', None) or 'callback')
>      for key in _get_tg_vars():
>          del template_vars[key]
>      response.headers['Content-Type'] = 'text/javascript'
>      return '%s(%s)' % (template_name, json_encode(template_vars))
>
> from myapp.config.app_cfg import base_config
> base_config.render_functions['jsonp'] = render_jsonp
> base_config.mimetype_lookup = {'.jsonp': 'text/javascript'}
>
> I've also added ahttp://trac.turbogears.org/ticket/2513for this.
>
> -- Christoph

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to