Widgets are making my xml ugly

3 views
Skip to first unread message

kerinin

unread,
Dec 2, 2006, 12:29:58 PM12/2/06
to TurboGears
Is there any way to make the XML produced by kid to look a little
cleaner? Every time I use a widget the XML that's produced looses it's
indentation. It would be nice if widget content was indented to match
the indentation of ${} call in the parent template. It makes it
difficult to read the code that's produced.

I know this is a minor issue, but it's annoying.

Christoph Zwerschke

unread,
Dec 2, 2006, 2:42:07 PM12/2/06
to turbo...@googlegroups.com

The serializers of the new Kid version 0.9.4 have a "format" argument.
You can specify all kinds of output formatting here, including
auto-indentation (see http://kid-templating.org/guide.html#id4).

Please don't confuse this with the "format" argument of the TurboGears
expose decorator which actually corresponds to the "output" argument of
Kid serializers and determines whether you want xml, html, xhtml or
plain format.

Currently the format feature is not well integrated because it was not
there when TurboKid was written. You probably have to use it that way:

import kid
format_pretty = kid.HTMLSerializer(doctype='html', format='pretty')

@expose(template="...", format=format_pretty)

I think it would be good to integrate TurboKid into the next Kid release
(or even better, support the more generic API that is also used for
Genshi), and make it more easy to specify Kid's output format.

But I need some TurboGears expert to tell me exactly which methods Kid
should provide to support this API so that we can get rid of TurboKid.
You can make comments or suggestions concerning this issue here:
http://www.kid-templating.org/trac/ticket/188

-- Christoph

kerinin

unread,
Dec 9, 2006, 3:27:57 PM12/9/06
to TurboGears
I tried adding this code, but it produced the following error:

--------------------------
Page handler: <function _wrapper at 0xb62d61ec>
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 105, in _run
self.main()
File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 254, in main
body = page_handler(*virtual_path, **self.params)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/identity/conditions.py",
line 275, in _wrapper
return fn( *args, **kw )
File "<string>", line 3, in default
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 334, in expose
output = database.run_with_transaction(
File "<string>", line 5, in run_with_transaction
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/database.py",
line 245, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 351, in <lambda>
mapping, fragment, args, kw)))
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 378, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/errorhandling.py",
line 71, in try_call
return func(self, *args, **kw)
File "/home/jackie/Projects/organizer/organizer/controllers.py", line
650, in default
return ctr.default(sect,sect_id,subsect,subsect_id,**kargs)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/identity/conditions.py",
line 275, in _wrapper
return fn( *args, **kw )
File "<string>", line 3, in default
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 330, in expose
output = func._expose(func, accept, func._allow_json,
File "<string>", line 5, in _expose
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 351, in <lambda>
mapping, fragment, args, kw)))
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0b2-py2.4.egg/turbogears/controllers.py",
line 389, in _execute_func
if template and template.startswith("."):
AttributeError: 'HTMLSerializer' object has no attribute 'startswith'
----------------------

It looks like turbogears is treating all format arguments as templates

Is this something I need to wait for future releases to use?

Christoph Zwerschke

unread,
Dec 9, 2006, 4:57:49 PM12/9/06
to turbo...@googlegroups.com
kerinin wrote:
> I tried adding this code, but it produced the following error:
> [...]

> It looks like turbogears is treating all format arguments as templates
> Is this something I need to wait for future releases to use?

This should work out of the box with TurboGears 1.0b2 and Kid 0.9.4
installed; I just tried it out. Can you show me the controllers.py file
that produced this error?

-- Chris

kerinin

unread,
Dec 10, 2006, 3:12:22 PM12/10/06
to TurboGears
OK, it seems to be working now. I think the problem was being caused
by redundant format=pretty calls. In some cases I'm exposing a
controller, and then returning another controller's output. I was
probably putting format=pretty in both the original and the called
controller's expose statement.

Reply all
Reply to author
Forward
0 new messages