From 10ddd756326df1fbe68d0489690f2bf9f03e1f8f Mon Sep 17 00:00:00 2001 From: James Turk Date: Sat, 22 May 2021 22:42:39 -0400 Subject: [PATCH] employee detail pages --- app.py | 22 ++++++--- data/employees.csv | 92 ++++++++++++++++++------------------- templates/staff.html | 6 +-- templates/staff_detail.html | 19 ++++++++ 4 files changed, 83 insertions(+), 56 deletions(-) create mode 100644 templates/staff_detail.html diff --git a/app.py b/app.py index b719106..3fdc169 100644 --- a/app.py +++ b/app.py @@ -3,10 +3,16 @@ from flask import Flask, render_template app = Flask(__name__) +_employees = {} + def employees(): - with open("data/employees.csv") as f: - employees = list(csv.DictReader(f)) + # thanks to http://www.figmentfly.com/bb/badguys3.html for names + global _employees + if not _employees: + with open("data/employees.csv") as f: + _employees = {e["id"]: e for e in csv.DictReader(f)} + return _employees @app.route("/") @@ -21,8 +27,12 @@ def about(): @app.route("/staff") def staff(): - # thanks to http://www.figmentfly.com/bb/badguys3.html for names - with open("data/employees.csv") as f: - employees = list(csv.DictReader(f)) + return render_template("staff.html", employees=employees().values()) - return render_template("staff.html", employees=employees) + +@app.route("/staff/") +def staff_detail(id_): + if employee := employees().get(id_): + return render_template("staff_detail.html", employee=employee) + else: + raise 404 diff --git a/data/employees.csv b/data/employees.csv index 4b9154b..2e9e49b 100644 --- a/data/employees.csv +++ b/data/employees.csv @@ -1,46 +1,46 @@ -first,last,position,status,children,hired -John,Barnett,Scheduling,Married,1,3/6/1963 -John,BigbootĂ©,Executive Vice President,Single,0,10/31/1938 -John,Camp,Human Resources,Single,0,6/12/1985 -John,Careful Walker,Accounting,Single,0,4/30/1990 -John,Chief Crier,"VP, Public Relations",Married,2,4/2/1980 -John,Cooper,Storage Acquisition,Single,0,8/15/1984 -John,Coyote,Medical Research,Married,6,1/1/1970 -John,Edwards,Public Relations,Divorced,2,8/15/1984 -John,Fat Eating,Craft Services,Single,0,8/15/1984 -John,Fish,Marine R&D,Divorced,12,10/31/1938 -John,Fledgling,Human Resources,Married,2,7/4/1976 -John,Gomez,"VP, Sales",Married,1,8/15/1984 -John,Grim,Actuary,Married,1.8,9/9/1970 -John,Guardian,Optical Systems Engineer,Single,0,6/9/1980 -John,Icicle Boy,Refrigeration R&D,Single,0,2/6/1939 -John,Jones,Government Relations,Married,3,8/15/1984 -John,Joseph,Government Relations,Married,2,10/31/1938 -John,Kim Chi,Craft Services,Married,2,7/24/1990 -John,Lee,Accounting,Single,0,12/14/1988 -John,Littlejohn,Staff Parlementarian,Divorced,0,10/31/1938 -John,Many Jars,Storage Acquisition Lead,Married,3,1/8/1960 -John,Milton,Chief Counsel,Single,2,6/6/1966 -John,Mud Head,Apian Research Lead,Married,7,1/2/1956 -John,Nephew,Temporal Paradox Resolution,Widowed,0,1/20/1474 -John,Nolan,Custodian,Married,2,10/31/1938 -John,O'Connor,Temporal Paradox Resolution,Widowed,1,5/15/2022 -John,Omar,Imports & Exports,Single,0,9/9/1963 -John,Parrot,Computer Design Specialist,Married,1,10/1/1970 -John,Rajeesh,Human Resources,Divorced,1,6/12/1982 -John,Ready to Fly,Aerial R&D,Married,1,7/4/1976 -John,Repeat Dance,Sales,Married,3,6/8/1949 -John,Roberts,Counsel,Married,0,4/1/1962 -John,Scott,Administration,Single,1,10/31/1938 -John,Shaw,Administration,Single,0,8/15/1984 -John,Small Berries,Orbital Ergonomitrics Team Leader,Married,3,10/17/1948 -John,Starbird,Orbital Ergonomitrics,Married,2,10/18/1948 -John,Take Cover,Security Administrator,Divorced,0,2/15/2019 -John,Thorny Stick,Sales,Married,0,8/15/1984 -John,Turk,System Administrator,Engaged,0,11/3/1986 -John,Two Horns,Paralegal,Married,0,8/15/1984 -John,Web,IT Support,Married,1,6/8/1949 -John,Whorfin,CEO / Lord,Single,0,10/31/1938 -John,Wood,Sales,Married,1,8/12/1948 -John,Wright,Orbital Mechanics Supervisor,Married,2,10/4/1985 -John,Ya Ya,Computer Design Specialist,Married,0,10/31/1938 \ No newline at end of file +id,first,last,position,status,children,hired +52,John,Barnett,Scheduling,Married,1,3/6/1963 +2,John,BigbootĂ©,Executive Vice President,Single,0,10/31/1938 +13,John,Camp,Human Resources,Single,0,6/12/1985 +14,John,Careful Walker,Accounting,Single,0,4/30/1990 +15,John,Chief Crier,"VP, Public Relations",Married,2,4/2/1980 +16,John,Cooper,Storage Acquisition,Single,0,8/15/1984 +17,John,Coyote,Medical Research,Married,6,1/1/1970 +18,John,Edwards,Public Relations,Divorced,2,8/15/1984 +19,John,Fat Eating,Craft Services,Single,0,8/15/1984 +20,John,Fish,Marine R&D,Divorced,12,10/31/1938 +21,John,Fledgling,Human Resources,Married,2,7/4/1976 +22,John,Gomez,"VP, Sales",Married,1,8/15/1984 +23,John,Grim,Actuary,Married,1.8,9/9/1970 +24,John,Guardian,Optical Systems Engineer,Single,0,6/9/1980 +25,John,Icicle Boy,Refrigeration R&D,Single,0,2/6/1939 +26,John,Jones,Government Relations,Married,3,8/15/1984 +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 +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 +33,John,Nephew,Temporal Paradox Resolution,Widowed,0,1/20/1474 +34,John,Nolan,Custodian,Married,2,10/31/1938 +35,John,O'Connor,Temporal Paradox Resolution,Widowed,1,5/15/2022 +37,John,Omar,Imports & Exports,Single,0,9/9/1963 +38,John,Parrot,Computer Design Specialist,Married,1,10/1/1970 +39,John,Rajeesh,Human Resources,Divorced,1,6/12/1982 +11,John,Ready to Fly,Aerial R&D,Married,1,7/4/1976 +40,John,Repeat Dance,Sales,Married,3,6/8/1949 +50,John,Roberts,Counsel,Married,0,4/1/1962 +51,John,Scott,Administration,Single,1,10/31/1938 +59,John,Shaw,Administration,Single,0,8/15/1984 +3,John,Small Berries,Orbital Ergonomitrics Team Leader,Married,3,10/17/1948 +4,John,Starbird,Orbital Ergonomitrics,Married,2,10/18/1948 +5,John,Take Cover,Security Administrator,Divorced,0,2/15/2019 +6,John,Thorny Stick,Sales,Married,0,8/15/1984 +7,John,Turk,System Administrator,Engaged,0,11/3/1986 +8,John,Two Horns,Paralegal,Married,0,8/15/1984 +9,John,Web,IT Support,Married,1,6/8/1949 +1,John,Whorfin,CEO / Lord,Single,0,10/31/1938 +99,John,Wood,Sales,Married,1,8/12/1948 +100,John,Wright,Orbital Mechanics Supervisor,Married,2,10/4/1985 +101,John,Ya Ya,Computer Design Specialist,Married,0,10/31/1938 diff --git a/templates/staff.html b/templates/staff.html index 9a2bd7d..59d5722 100644 --- a/templates/staff.html +++ b/templates/staff.html @@ -10,8 +10,7 @@ First Name Last Name Position Name - Status - Hired +   @@ -20,8 +19,7 @@ {{ e.first }} {{ e.last }} {{ e.position }} - {{ e.status }}, {{ e.children }} children - {{ e.hired }} + Details {% endfor %} diff --git a/templates/staff_detail.html b/templates/staff_detail.html new file mode 100644 index 0000000..9d5f480 --- /dev/null +++ b/templates/staff_detail.html @@ -0,0 +1,19 @@ +{% extends "base.html" %} + +{% block base %} +
+

Employee Details for {{ employee.first }} {{ employee.last }}

+
+
+
Position
+
{{ employee.position }}
+
Marital Status
+
{{ employee.status }}
+
Number of Children
+
{{ employee.children }}
+
Hired
+
{{ employee.hired }}
+
+
+
+{% endblock %}