Skip to content

Commit d011755

Browse files
committed
* add in-class lab work
1 parent 73cd242 commit d011755

File tree

27 files changed

+588
-0
lines changed

27 files changed

+588
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from flask import Flask
2+
import bookdb
3+
4+
app = Flask(__name__)
5+
6+
db = bookdb.BookDB()
7+
8+
9+
@app.route('/')
10+
def books():
11+
# put code here that provides a list of books to a template named
12+
# "book_list.html"
13+
pass
14+
15+
16+
@app.route('/book/<book_id>/')
17+
def book(book_id):
18+
# put code here that provides the details of a single book to a template
19+
# named "book_detail.html"
20+
pass
21+
22+
23+
if __name__ == '__main__':
24+
app.run(debug=True)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
3+
class BookDB():
4+
def titles(self):
5+
titles = [dict(id=id, title=database[id]['title']) for id in database.keys()]
6+
return titles
7+
8+
def title_info(self, id):
9+
return database[id]
10+
11+
12+
# let's pretend we're getting this information from a database somewhere
13+
database = {
14+
'id1' : {'title' : 'CherryPy Essentials: Rapid Python Web Application Development',
15+
'isbn' : '978-1904811848',
16+
'publisher' : 'Packt Publishing (March 31, 2007)',
17+
'author' : 'Sylvain Hellegouarch',
18+
},
19+
'id2' : {'title' : 'Python for Software Design: How to Think Like a Computer Scientist',
20+
'isbn' : '978-0521725965',
21+
'publisher' : 'Cambridge University Press; 1 edition (March 16, 2009)',
22+
'author' : 'Allen B. Downey',
23+
},
24+
'id3' : {'title' : 'Foundations of Python Network Programming',
25+
'isbn' : '978-1430230038',
26+
'publisher' : 'Apress; 2 edition (December 21, 2010)',
27+
'author' : 'John Goerzen',
28+
},
29+
'id4' : {'title' : 'Python Cookbook, Second Edition',
30+
'isbn' : '978-0-596-00797-3',
31+
'publisher' : 'O''Reilly Media',
32+
'author' : 'Alex Martelli, Anna Ravenscroft, David Ascher',
33+
},
34+
'id5' : {'title' : 'The Pragmatic Programmer: From Journeyman to Master',
35+
'isbn' : '978-0201616224',
36+
'publisher' : 'Addison-Wesley Professional (October 30, 1999)',
37+
'author' : 'Andrew Hunt, David Thomas',
38+
},
39+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title></title>
5+
</head>
6+
<body>
7+
<!-- fill out the template with the details of the given book -->
8+
</body>
9+
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>Python Books</title>
5+
</head>
6+
<body>
7+
<h1>Summer Reading</h1>
8+
<p>Here's a list of books you might enjoy. Click a title to read more
9+
about that book.</p>
10+
<!-- fill out this template with your list -->
11+
</body>
12+
</html>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from flask import Flask
2+
3+
4+
# configuration goes here
5+
6+
7+
app = Flask(__name__)
8+
9+
10+
if __name__ == '__main__':
11+
app.run(debug=True)

assignments/week05/lab/flaskr_1/flaskr_tests.py

Whitespace-only changes.

assignments/week05/lab/flaskr_1/schema.sql

Whitespace-only changes.

assignments/week05/lab/flaskr_1/static/.gitignore

Whitespace-only changes.

assignments/week05/lab/flaskr_1/templates/.gitignore

Whitespace-only changes.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sqlite3
2+
from contextlib import closing
3+
4+
from flask import Flask
5+
6+
7+
# configuration goes here
8+
DATABASE = '/tmp/flaskr.db'
9+
SECRET_KEY = 'development key'
10+
11+
app = Flask(__name__)
12+
app.config.from_object(__name__)
13+
14+
15+
def connect_db():
16+
return sqlite3.connect(app.config['DATABASE'])
17+
18+
19+
def init_db():
20+
with closing(connect_db()) as db:
21+
with app.open_resource('schema.sql') as f:
22+
db.cursor().executescript(f.read())
23+
db.commit()
24+
25+
26+
if __name__ == '__main__':
27+
app.run(debug=True)

0 commit comments

Comments
 (0)