Friday, August 24, 2007

Genshi Templates: include and select()

Hint for today: If you don't know Xpath select stuff at all (like I didn't a couple minutes ago) and you want your Turbogears templates to be a little more intelligent about column content placement, you can do something like this:

<!-- in master.html -->
<div id="centercontent">
<div id="status_block" py:if="tg_flash"
class="flash" py:content="tg_flash">
<div id="rightcontent">

<!-- in welcome.html -->
<div id="centercontent">
<!-- all your base here -->
<div id="rightcontent">
<!-- navigation stuff here -->

Breaking down the Xpath select statement a little more (removing the quote escapes):
//div == in all 'div' elements
[@id='centercontent'] == where the (@) attribute 'id' is equal to 'centercontent'
/* == select all the children elements

Tuesday, August 14, 2007

Coolest Hotel Design Ever - Eco-Aqua Hotel in a Quarry

It won't be completed for at least another 2 years, but I would so fly to china just to stay here:

It's already cool enough that they're apparently using an old quarry as a lake, so the whole thing is sunk into a pit and looks like an especially fantastical Bryce creation, or that they're using geothermal power. The thing that drops my jaw is the ginormous *waterfall-like elevator* that apparently runs over the glass face of the building. A
t least, I think it's an elevator.

Really nice flash sketch widget

I really like the texture aesthetic of this online sketch app, it's the best I've seen. I really like the background "paper," he thinner-line tools resemble actual penstrokes (after they're scanned, anyway).

If only I had a spare second to doodle :)

Thursday, August 09, 2007

Really Awesome Ad.

This is the best ad I've seen in a long, long time. Well, the iphone ads are really, really good and everything, but they do lack in a certain... initial bafflement. :D

Sunday, August 05, 2007

Website Teaser

It's coming! Got my domain name, got hosting through Webfaction, who gives half their turbogears related signup fees to the turbogears project. They keep on top of tech, I like it, and I like the hosting so far. Site is running in Turbogears on Python of course.

More to come in the future. :)

Saturday, August 04, 2007

Turbogears Banner

I couldn't find a small Turbogears banner / logo / powered by image to my liking, so I just whipped one up. Also, here's a Python logo I found through a google search. Enjoy.

Wednesday, August 01, 2007

reCAPTCHA: Stop Spam, Read Books

This is by far the coolest captcha service ever. (Blogger, you should pick this up) Out of Carnegie Mellon, this service aids in digitizing books. It gives you two words to type, the first is a known word, the second is a word that their OCR algorithm couldn't figure out. If you get the first word right, it assumes that you also got the second word correct.

I think it's a fantastic idea, putting captchas to a good purpose. :)

Gotcha: Turbogears Form Widget

So, I had one of those barking up the wrong tree moments this morning, where I was sure as can be there was something going on with SQLObject caching, but it turned out to be much simpler than that. I have a simple sort of application linking products to the company that makes them, but when you added a new company, then tried to add a new product for that company, the company didn't show up in the pull down box. (a SingleSelectField)

As it turns out, when you create your form widget:
editform = widgets.TableForm(
the field class gets created once, at the controller load, and that's it.
Therefore, if you populate your fields when you create the form, they won't be updated, possibly causing you to learn more than you wanted to about SQLObject caching. I found the solution on this page. Similar to passing values, you just pass a dictionary of the options to the appropriate widget. Since I have a generic CRUD controller, I created a function in my EditFields class that returns a dictionary of all the options fields and updated values, like so:
def updatelists(self):
"""Return a dictionary of any lists
that need to be updated due to new objects"""

companylist = Company.build_list(

#in my form, companyID is the
#name of the SingleSelectField
return dict(companyID=companylist )

(using the build_list method here) then, in my controller:
return dict( form=self.editform,
and finally, in my model:
<div py:content="ET(form.display(
(I'm using Genshi, which is why I have the ET function there)