Wednesday, September 26, 2007

Toscawidgets Forms: Passing Compound Widgets

For lack of documentation's sake, and because it wasn't initially obvious to me after poking around in the code (in fact, I got led astray, thinking there was some dot notation I would have to use), this is how you pass values into Compound Widgets in Toscawidgets:

Say you have some Widget like this:
form = Form('FormName',

and displayed in your template like this:

${ form.display(**form_args)}

then you can pass values into it from your controller like so:
def controller(self):
return dict(form=form,
'FieldSetName':{ 'TextFieldName':
'Desired TextField Value'}}})

I guess it's pretty obvious in retrospect, in fact, the compound Form outputs something much like this (minus the outside dictionary), and those values can be passed right back into the Compound Form again. Perhaps, had I been actually using a Model, or gotten more sleep, this all would have been more natural - but hopefully this helps someone else.

Hint: If you're overriding templates, be sure that you're still passing the right values in to fetch the children arguments, i.e.:

${section.display(value_for(section), **args_for(section))}

Monday, September 24, 2007

Aardvark: Must have Firefox Extension

Any discussion on Firefox Extension recommendations must include the obligatory "Firebug is the most amazing tool ever" note. (Because it's really fantastically useful, and it just keeps getting better)

Today, I'd like to mention Aardvark. It's super useful for isolating parts of the page for easy printing, and quite easy to use, once you learn the keystrokes. I use it all the time for printing out comics and lolcats for posting on my cubical walls.

Gotcha: Toscawidgets and Mochikit

So, after much annoyingness, I've finally realized why I was having so much trouble using the Mochikit extension to Toscawidgets. As the Toscawidgets docs state, you need to include this template if you're using Genshi, which basically adds these lines (plus matching matching body top and bottom lines):

<link for=\"css in tg_css\" replace=\"css.display()\">
<link for=\"js in tg_js_head\" replace=\"js.display()\">

Now, if you're silly, like me, and don't really pay attention, you just include it, without looking too hard at your master template, which includes these lines by default:

<link for=\"css in tg_css\" replace=\"ET(css.display())\">
<link for=\"js in tg_js_head\" replace=\"ET(js.display())\">

As soon as you put the widget in your controller:

from toscawidgets.widgets.mochikit import mochikit
class Root(controllers.RootController):
def info(self):
return dict( form = InformationForm,
js = mochikit )

You start to get funny Genshi errors, mine was "AttributeError: 'Stream' object has no attribute 'tag'" which prompted me to try various combinations of adding ET() and HTML() to my templates, when the problem was that Toscawidgets cleans that whole ET/Genshi issue up and breaks when you leave them in.

So, long story short, add the site template and remove the conflicting lines from your master template. (Though, if you are mixing Toscawidgets and Turbogears widgets, you'll have to do something like what's outlined here.)

Wednesday, September 12, 2007

Security Camera Shenanigans

One of the funniest things I've seen in a while: At the Port Authority in Tampa, they have a whole bunch of security cameras, in a really nice movie looking setup. Unlike the movies, though, a whole colony of ants has built a highway across one, so it looks like something out of Them!.. and on another camera, a huge fuzzy spider crawling about a pier. It was quite alarming at first, out of the corner of my eye, but ultimately quite amusing. I wish I could have taken a picture, but I doubt they would like me whipping out a camera in their security room.

Tuesday, September 11, 2007

Announcement: GenshiColumnTemplate

I've made a quickstart Genshi template for Turbogears that gives you a ready made 3 column layout, using the excellent 3 column layout from A List Apart's Holy Grail article. If you spent 5 minutes, you could do it yourself, but it's kinda nice to have something ready made. I pull out the layout css in a separate file, and relaid out the welcome page to use 3 columns. The master.html template uses Genshi's Xpath select function to pull content together into the columns.

To Install:
easy_install genshicolumntemplate

To Use:
In your templates that include master.html, make divs that have ids of 'left', 'center', 'right', 'footer', and 'header', or just add your static content to master.html. The only caveat is that there must be some sort of other element inside the positional div wrapping your text, it can't be just text, as xpath won't select it for replacement.

  • Documentation. It should be mercifully short, yet I still haven't done it
  • Fix up the welcome page a bit
  • Figure out some sort of decent unit test for templates
  • Wait for suggestions, criticisms, etc :)
Please let me know if you try it out.

Monday, September 10, 2007

Python Cheeseshop and Eggs

I've been playing with putting a package up on the Cheeseshop, Python's Package Index. There isn't a lot of documentation out there, but there really doesn't need to be, it's pretty easy. I cheated and modified someone else's egg for my own use, but the file setup isn't all that hard, and you can get paster to make a ready-eggable template for you.

Anyways, the quick commands to use, after creating an account and setting up your egg and metadata:

  • python register
    this creates an entry in the cheeseshop for your project and populates it with the metadata from your egg. If something is wrong, just fix it and rerun this command.
  • python sdist upload
    this creates a source distribution (the egg folder tarred and gunzipped) in dist/ and uploads it to the cheeseshop
  • python bdist_egg
    upload this creates a binary distribution (the egg folder all zipped up) in dist/ and uploads it to the cheeseshop

Super bonus hints:
python develop installs the egg using a link to your source code instead of putting it in the site-packages folder, so you can test things.
easy_install -m package_name
takes the package name out of the appropriate places, allowing you to uninstall a package by deleting it from the site-packages folder.

Sunday, September 02, 2007

Toscawidgets and Paster

So, I'm playing around with making a bunch of Toscawidgets (Toscawidgets widgets?) and found, by hunting around a bit, that you can get a pretty handy package template by using PasteScript. Try:
paster create -t toscawidgets
and answer the questions. For a list of what other templates paster create has, try:
paster create --list-templates
For some reason, figuring this out took me way longer than it really should have last night. (Thanks Daniel)

A super bonus bbedit command line hint: bbedit *.py --new-window