/
hackbright-web.py
93 lines (63 loc) · 2.44 KB
/
hackbright-web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, request, render_template
import hackbright
app = Flask(__name__)
@app.route("/create-student")
def get_new_student_form():
"""Show form for entering a new student into the database"""
return render_template("create_student.html")
@app.route("/new-student", methods=['POST'])
def add_student():
"""Add student to database and display confirmation"""
# get student data from form
first_name = request.form.get('fname')
last_name = request.form.get('lname')
github = request.form.get('github')
# insert student info into table
hackbright.make_new_student(first_name, last_name, github)
# render confirmation page (with link to student page)
return render_template("new_student.html",
first=first_name,
last=last_name,
github=github)
@app.route("/project")
def get_project():
"""Show information about a project"""
# should show title, description, and maximum grade
title = request.args.get('name')
info = hackbright.get_project_by_title(title)
title = info[0]
description = info[1]
max_grade = info[2]
return render_template("project_info.html",
title=title,
description=description,
max_grade=max_grade)
@app.route("/project-search")
def get_project_form():
"""Show form for searching for a project."""
projects = hackbright.get_all_projects()
return render_template("project_search.html",
projects=projects)
@app.route("/student")
def get_student():
"""Show information about a student."""
# run select statement, bind 'github' to resulting tuple
github = request.args.get('github', 'jhacks')
# unpack tuple
first, last, github = hackbright.get_student_by_github(github)
# list of tuples (project, grade)
all_grades = hackbright.get_grades_by_github(github)
# render student info page
html = render_template("student_info.html",
first=first,
last=last,
github=github,
all_grades=all_grades)
return html
@app.route("/student-search")
def get_student_form():
"""Show form for searching for a student."""
return render_template("student_search.html")
if __name__ == "__main__":
hackbright.connect_to_db(app)
app.run(debug=True)