Browse Dogs Assignment

For this assignment you will extend a Flask app by adding an additional view of a database of dogs.

Database

You are given a SQLite database named dogs.sqlite which is already populated. Here is the schema:

CREATE TABLE breed(id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE owner(id INTEGER PRIMARY KEY, name TEXT);
CREATE TABLE dog(id INTEGER PRIMARY KEY, owner_id INTEGER, breed_id INTEGER,
                 name TEXT, age INTEGER,
                 FOREIGN KEY(owner_id) REFERENCES owner(id),
                 FOREIGN KEY(breed_id) REFERENCES breed(id));

Existing Code

Run the Flask app in browse_dogs.py to see the site as it currently exists. See the comments in flask_and_sqlite.py from the in-class activity for a quick reminder of the steps needed to get a Flask app going, or read the venv and Flask guide for more detailed instructions.

When you go to the page served by the app, you will see a list of dogs. This is served by the function names() in browse_dogs.py. If you click on the “View by breed” link, you will be taken to another page which shows the dogs organized by breed. This other page is served by the function breeds(). Note that this other page has the string /breeds at the end of its URL and breeds() has the decorator @app.route('/breeds'). This is how Flask knows to run breeds() when you add /breeds to the end of the URL.

Read through browse_dogs.py and the 2 template HTML files to understand how the current app works. Note that the breeds.html template uses a dictionary named dogs_by_breed which is a dictionary of lists. It uses a nested loop to loop over all the breeds, and then each dog within each breed.

Browsing by Owner

Add a function which serves a third page to browse the dogs by owner. This page should be served when visiting /owners and the template should be in templates/owners.html. For each owner, put their name in an <h2> tag (see breeds.html for an example), and then list all of the owner’s dogs. For each dog, show the name, breed, and age of the dog.

Add links to each HTML template so that you can jump to either of the other 2 pages from any of the 3 pages. See the existing HTML files to see how links are created. This is the general form to create a link:

<a href="target">link text</a>

You may want to run some queries on the database manually using the sqlite3 command line tool to see all of the data to ensure you are displaying all of it correctly.

Submission

Add, commit, and push your modified browse_dogs.py and the 3 template files. Do not add any other files to the repository.

In addition to the above requirements, your code must be PEP 8 compliant for full credit. PEP 8 compliance is checked automatically, the rest of the code will be checked manually.