merge yoyodyne
This commit is contained in:
parent
d8139fbfd3
commit
04017261fc
46
data/employees.csv
Normal file
46
data/employees.csv
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
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
|
||||||
|
404,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 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
|
||||||
|
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
|
|
17
scrapple/__init__.py
Normal file
17
scrapple/__init__.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from flask import Flask, render_template
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
# common routes
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
return render_template("index.html")
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/about")
|
||||||
|
def about():
|
||||||
|
return render_template("about.html")
|
||||||
|
|
||||||
|
|
||||||
|
from . import parks
|
||||||
|
from . import yoyodyne
|
@ -1,28 +1,17 @@
|
|||||||
import json
|
import json
|
||||||
import math
|
import math
|
||||||
from flask import Flask, render_template, abort, request
|
from . import app
|
||||||
|
from flask import render_template, abort, request
|
||||||
|
|
||||||
app = Flask(__name__)
|
_parks = {}
|
||||||
|
|
||||||
_data = {}
|
|
||||||
|
|
||||||
|
|
||||||
def parks():
|
def parks():
|
||||||
global _data
|
global _parks
|
||||||
if not _data:
|
if not _parks:
|
||||||
with open("data/parks.json") as f:
|
with open("data/parks.json") as f:
|
||||||
_data = {int(p["id"]): p for p in json.load(f)}
|
_parks = {int(p["id"]): p for p in json.load(f)}
|
||||||
return _data
|
return _parks
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
|
||||||
def index():
|
|
||||||
return render_template("index.html")
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/about")
|
|
||||||
def about():
|
|
||||||
return render_template("about.html")
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/parks")
|
@app.route("/parks")
|
26
scrapple/templates/awards.html
Normal file
26
scrapple/templates/awards.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block base %}
|
||||||
|
<div class="card fluid">
|
||||||
|
<h1 class="section">Yoyodyne Propulsion Systems <small>Awards</small></h1>
|
||||||
|
<div class="section">
|
||||||
|
<div class="row">
|
||||||
|
|
||||||
|
{% for award in awards %}
|
||||||
|
<div class="card large">
|
||||||
|
<div class="section">
|
||||||
|
<h2>{{ award.name }} <small>{{ award.year }}</small></h2>
|
||||||
|
<dl>
|
||||||
|
<dt>For<dt>
|
||||||
|
<dd>{{ award.for }}</dd>
|
||||||
|
<dt>Awarded To</dt>
|
||||||
|
<dd>{{ award.to }}</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
40
scrapple/templates/staff.html
Normal file
40
scrapple/templates/staff.html
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block base %}
|
||||||
|
<div class="card fluid">
|
||||||
|
<h1 class="section">Yoyodyne Propulsion Systems <small>Staff Roster</small></h1>
|
||||||
|
<div class="section">
|
||||||
|
<table id="employees" style="max-height: 100%;">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>First Name</th>
|
||||||
|
<th>Last Name</th>
|
||||||
|
<th>Position Name</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for e in employees %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ e.first }}</td>
|
||||||
|
<td>{{ e.last }}</td>
|
||||||
|
<td>{{ e.position }}</td>
|
||||||
|
<td><a href="/staff/{{ e.id }}">Details</a></td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div style="display: grid; grid-template-columns: auto auto;">
|
||||||
|
{% if prev_page %}
|
||||||
|
<a class="button" href="?page={{ prev_page }}" style="justify-self: start;">« Previous</a>
|
||||||
|
{% else %}
|
||||||
|
<!-- for grid spacing -->
|
||||||
|
<span> </span>
|
||||||
|
{% endif %}
|
||||||
|
{% if next_page %}
|
||||||
|
<a class="button" style="justify-self: end;" href="?page={{ next_page }}">Next »</a>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
19
scrapple/templates/staff_detail.html
Normal file
19
scrapple/templates/staff_detail.html
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block base %}
|
||||||
|
<div class="card fluid">
|
||||||
|
<h2 class="section">Employee Details for {{ employee.first }} {{ employee.last }}</h2>
|
||||||
|
<div class="section">
|
||||||
|
<dl>
|
||||||
|
<dt>Position</dt>
|
||||||
|
<dd id="position">{{ employee.position }}</dd>
|
||||||
|
<dt>Marital Status</dt>
|
||||||
|
<dd id="status">{{ employee.status }}</dd>
|
||||||
|
<dt>Number of Children</dt>
|
||||||
|
<dd id="children">{{ employee.children }}</dd>
|
||||||
|
<dt>Hired</dt>
|
||||||
|
<dd id="hired">{{ employee.hired }}</dd>
|
||||||
|
</dl>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
109
scrapple/yoyodyne.py
Normal file
109
scrapple/yoyodyne.py
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
import csv
|
||||||
|
import math
|
||||||
|
from . import app
|
||||||
|
from flask import render_template, abort, request
|
||||||
|
|
||||||
|
|
||||||
|
_employees = {}
|
||||||
|
|
||||||
|
|
||||||
|
def employees():
|
||||||
|
# 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("/awards")
|
||||||
|
def awards():
|
||||||
|
award_data = [
|
||||||
|
{
|
||||||
|
"name": "Nobel Prize in Physics",
|
||||||
|
"year": "1934",
|
||||||
|
"for": "Discovery of the 8th Dimension",
|
||||||
|
"to": "John Whorfin",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cousteau Society Award",
|
||||||
|
"year": "1989",
|
||||||
|
"for": "Uses of Cephalopod Intelligence",
|
||||||
|
"to": "John Fish",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Best Supporting Actor",
|
||||||
|
"year": "1985",
|
||||||
|
"for": "John Lithgow Biopic",
|
||||||
|
"to": "John Whorfin",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Nobel Prize in Physics",
|
||||||
|
"year": "2986",
|
||||||
|
"for": "Temporal Paradox Resolution",
|
||||||
|
"to": "John O'Connor",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Paralegal of the Year",
|
||||||
|
"year": "1999",
|
||||||
|
"for": "Paralegal Activity",
|
||||||
|
"to": "John Two Horns",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "ACM Award",
|
||||||
|
"year": "1986",
|
||||||
|
"for": "Innovations in User Interface",
|
||||||
|
"to": "John Ya Ya",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "2nd Place, Most Jars Category",
|
||||||
|
"year": "1987",
|
||||||
|
"for": "Jars",
|
||||||
|
"to": "John Many Jars",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Album of the Year",
|
||||||
|
"year": "1997",
|
||||||
|
"for": "Space Coyote",
|
||||||
|
"to": "John Coyote",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Most Creative Loophole",
|
||||||
|
"year": "1985",
|
||||||
|
"for": "Innovation in Interdimensional Tax Shelters",
|
||||||
|
"to": "John Lee",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
return render_template("awards.html", awards=award_data)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/staff")
|
||||||
|
def staff():
|
||||||
|
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/<id_>")
|
||||||
|
def staff_detail(id_):
|
||||||
|
if id_ == "404":
|
||||||
|
abort(
|
||||||
|
404,
|
||||||
|
"This page intentionally left blank. (No really! This is an intentional error for demonstration purposes.)",
|
||||||
|
)
|
||||||
|
if employee := employees().get(id_):
|
||||||
|
return render_template("staff_detail.html", employee=employee)
|
||||||
|
else:
|
||||||
|
abort(404)
|
Loading…
Reference in New Issue
Block a user