db rewrite

Reworks db.py with the goal of making the code easier to read, understand, and extend. I also added flagging sources in the db. Still needs some work to DRY it out and add error handling, but I think this is a good direction. Feedback appreciated!

Note that you may need to rm your db_development.sqlite, then run `python -c "import db; db.init_db()"` because the tables have changed.