Permalink
Browse files

Comments added.

  • Loading branch information...
1 parent a63d129 commit 2a5765c30e337bace2b5f09c8cf16f015cf6e6cb @jeremyjbowers jeremyjbowers committed Feb 28, 2013
Showing with 34 additions and 0 deletions.
  1. +21 −0 projects/fdic/app.py
  2. +13 −0 projects/fdic/models.py
View
@@ -1,34 +1,55 @@
+# Flask is what makes everything work. Import it.
from flask import Flask, render_template
+# Import our bank model.
from models import Bank
+# Flask needs to run! This gives it legs.
app = Flask(__name__)
+# Routes!
@app.route('/', methods=['GET'])
def failed_banks_list():
+ """
+ This route is for a list of ALL banks.
+ """
+ # The context for this pages is just "banks", a list of all banks.
context = {
'banks': Bank.select()
}
+ # Render the template to list.html and with the context from above.
return render_template('list.html', **context)
@app.route('/bank/<cert_num>/', methods=['GET'])
def failed_bank_detail(cert_num):
+ """
+ This route is for a single bank.
+ We're going to do TWO things.
+ a.) We're going to get the one bank.
+ b.) We're going to get all banks EXCEPT this bank in the same state.
+ """
+ # a.) Get this bank.
this_bank = Bank.select()\
.where(Bank.cert_num == int(cert_num)).get()
+
+ # b.) Get the other banks in this state.
same_state_banks = Bank.select()\
.where(Bank.state == this_bank.state)\
.where(Bank.cert_num != int(cert_num))
+ # Set up the context; include both this bank and other banks from this state.
context = {
'bank': this_bank,
'same_state_banks': same_state_banks
}
+ # Render the template to detail.html and with that context.
return render_template('detail.html', **context)
+# Last bit! Just need to get flask to run when we run it.
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True)
View
@@ -1,9 +1,15 @@
+# Import our library.
from peewee import *
+# Connect to the DB.
db = SqliteDatabase('fdic.sqlite')
+# Set up a bank.
class Bank(Model):
+ """
+ This defines a bank and all of the fields a bank has.
+ """
bank = CharField()
city = CharField()
state = CharField()
@@ -13,6 +19,13 @@ class Bank(Model):
updated = DateField()
url = CharField()
+ # What is this thing?
class Meta:
+ """
+ It's a class INSIDE a class.
+ Don't let that bother you.
+ We need to attach this model to a database.
+ Also, we need to point to Schnaars's table.
+ """
database = db
db_table = 'failed_banks'

0 comments on commit 2a5765c

Please sign in to comment.