diff --git a/app.py b/app.py index 6078e23..10ca127 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,6 @@ import csv -from flask import Flask, render_template, abort +import math +from flask import Flask, render_template, abort, request app = Flask(__name__) @@ -27,7 +28,21 @@ def about(): @app.route("/staff") def staff(): - return render_template("staff.html", employees=employees().values()) + page = int(request.args.get("page", 1)) + per_page = 10 + total_items = len(employees()) + max_page = math.ceil(total_items / per_page) + print(max_page) + if page < 1 or page > max_page: + abort(404) + page_employees = list(employees().values())[(page - 1) * per_page : page * per_page] + return render_template( + "staff.html", + employees=page_employees, + page=page, + prev_page=page - 1, + next_page=page + 1 if page < max_page else None, + ) @app.route("/staff/") diff --git a/data/employees.csv b/data/employees.csv index 2e9e49b..f7068c6 100644 --- a/data/employees.csv +++ b/data/employees.csv @@ -18,7 +18,7 @@ id,first,last,position,status,children,hired 27,John,Joseph,Government Relations,Married,2,10/31/1938 28,John,Kim Chi,Craft Services,Married,2,7/24/1990 29,John,Lee,Accounting,Single,0,12/14/1988 -30,John,Littlejohn,Staff Parlementarian,Divorced,0,10/31/1938 +30,John,Littlejohn,Staff Parliamentarian,Divorced,0,10/31/1938 31,John,Many Jars,Storage Acquisition Lead,Married,3,1/8/1960 666,John,Milton,Chief Counsel,Single,2,6/6/1966 32,John,Mud Head,Apian Research Lead,Married,7,1/2/1956 diff --git a/templates/staff.html b/templates/staff.html index 9703abd..485661f 100644 --- a/templates/staff.html +++ b/templates/staff.html @@ -4,7 +4,7 @@

Yoyodyne Propulsion Systems Staff Roster

- +
@@ -24,6 +24,17 @@ {% endfor %}
First Name
+
+ {% if prev_page %} + « Previous + {% else %} + +   + {% endif %} + {% if next_page %} + Next » + {% endif %} +
{% endblock %}