Elvelind Grandin wrote:
> @expose("stringTemplate:.welcome", as_format="text")
> @expose(".templates.xml", accept_format="xml/foo")
> @expose("json")
> @expose(".templates.welcome")
> def ..
Hi Elvelind,
I'm trying to get something in this line working in a project but can't
seem to get it right:
@turbogears.expose("webpanel.templates.list")
@turbogears.expose("json")
def index(self, origin=None, destination=None):
format = cherrypy.request.params.get("tg_format", "default")
print "%s,%s,%s" % (origin, destination, format)
if format == "json":
return dict(message="returning json")
else:
return dict(
list_widget=self.list_widget,
data=self.sql_class.select(user_items(self.sql_class)),
)
When I pass tg_format=json as a GET param I get (sic):
Page handler: <bound method AliasController.index of
<webpanel.mailbox.controllers.AliasController object at 0x20f5490>>
Traceback (most recent call last):
File
"/sw/lib/python2.4/site-packages/CherryPy-2.2.0-py2.4.egg/cherrypy/_cphttptools.py",
line 106, in _run
self.main()
File
"/sw/lib/python2.4/site-packages/CherryPy-2.2.0-py2.4.egg/cherrypy/_cphttptools.py",
line 255, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in index
File "/Users/alberto/src/turbogears/turbogears/controllers.py", line
206, in expose
output = database.run_with_transaction(expose._expose,func, accept,
allow_json, allow_json_from_config,*args, **kw)
File "turbogears/database.py", line 216, in run_with_transaction
File "<string>", line 5, in _expose
File "_speedups.pyx", line 376, in
_speedups.BaseDispatcher.__getitem__
File
"build/bdist.darwin-8.4.0-Power_Macintosh/egg/dispatch/interfaces.py",
line 15, in __call__
NoApplicableMethods: ((<function index at 0x209dc70>,
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
None, False, (<webpanel.mailbox.controllers.AliasController object at
0x20f5490>,), {'origin': None, 'tg_format': 'json', 'destination':
None}), {})
And when no tg_format param is passed a jsonify exception is raised
which means that expose is treating it as if tg_format was json (and
trying to jsonfiy the grid widget).
Am I missing something?
I'll explain what I'm trying to accomplish in case there's a better way
to do it: I want to display a fastdata grid on default format and feed
JSON data into a AjaxDataGrid on "tg_format=json".
Unfortunately, they expect data in slightly different formats so I need
to branch depending on tg_format to feed them them correct dict.
As a suggestion, a 'branch_to' (or better name) optional arg that
branched to another method ( a là error_handler) will be very nice to
support this kind of behavior without the ugly lookup at request.params
Thanks for any help,
Alberto
P.S Using r1127
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears Trunk" 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-trunk
-~----------~----~----~----~------~----~------~--~---