betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

17 August 2011

Chameleon PT Checkboxes

It's the same... almost the same

With pyramid, web developers have the choice to use various templating engines. Coming from Zope, "Chameleon ZPT Templates" are a good choice, as they are compatible to the ZPTs I've gotten used to over the years. The thing is, these templates are compatible, but there are differences.

One thing that had me wondering was how to set the "checked" attribute on checkbox input fields. In Zope's ZTPs, you can do something like tal:attributes="checked somevariable" and if somevariable is evaluated to True, then the checked-attribute will be set to "checked", otherwise it will not be there at all. It's a special case that is necessary for the way some browsers handle this attribute.

In Chameleon's PT, I got a lot of "None type is not callable" errors, or else it would show the box as checked when it shouldn't... and I was overall confused. Turns out the incantation that works for me here is something like this: tal:attributes="checked 'checked' if somevariable else None". It seems in order to not insert the "checked" attribute, Chameleon PT wants the value to be None, but it doesn't like python's True for a value either, therefore putting in the string 'checked'.


Posted by betabug at 09:56 | Comments (0) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Cory Doctorow's Little Brother | Main | Reading on Board >>
Comments
There are no comments.
Trackbacks
You can trackback to: http://betabug.ch/blogs/ch-athens/1203/tbping
There are no trackbacks.
Leave a comment