Horrible code in the controller and template, but oh well, it's late, and it's getting there at least.