Blog Archive for December 19, 2009

jQuery Click Event

December 19, 2009

Here's some example code for handling a click event on a header, then loading some html from a URL into the next div down the page.

HTML

This HTML was generated from a django template, so there was one h3 per year.

<div id="years">
{%for year in Years ...

Bind Variables with Python and Postgres

December 19, 2009

When executing SQL against Postgres with python, the bind variable format is different from that used for Oracle.

lCursor = connection.cursor()
lCursor.execute("""SELECT event.date_of_event, 
                         event.name, 
                         contest.slug, 
                         contest.name,  
                         event.id, 
                         contest.id 
                   FROM contests_contest contest, contests_contestevent event 
                   WHERE event.owner_id = %(userid)s 
                   AND event.contest_id = contest ...

Sorting a Python Dictionary

December 19, 2009

Dictionaries in python are unordered. What you can do is get the keys, sort them, and then produce a new dictionary in the order you want.

lYearNumbers = lYears.items()
lYearNumbers.sort()
lYearNumbers.reverse()
lYears = [value for key, value in lYearNumbers]

This code gets the keys from the lYears dictionary, sorts ...

Postgres psql Quick Reference

December 19, 2009

psql commands

  • \q - quit
  • \l - list databases
  • \d - list schema objects
  • \dt - list tables
  • \g [filename] - output results of query buffer to a file
  • \o [filename] - output results of session to a file
  • \i [filename] - run commands in file

Altering Table

  • Rename Column - alter table contests_contest rename column "order" to ...