-
Notifications
You must be signed in to change notification settings - Fork 0
/
hackbright-web.py
77 lines (53 loc) · 2.53 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
from flask import Flask, request, render_template
import hackbright
app = Flask(__name__)
@app.route("/student")
def get_student():
"""Show information about a student."""
github = request.args.get('github', 'jhacks')
first, last, github = hackbright.get_student_by_github(github)
projects_grades = hackbright.get_grades_by_github(github)
html = render_template("student_info.html",
first=first,
last=last,
github=github,
projects_grades=projects_grades)
return html
@app.route("/student-search")
def get_student_form():
"""Show form for searching for a student."""
return render_template("student_search.html")
@app.route("/new-student")
def add_student():
"""Show form for adding a new student."""
return render_template("new_student.html")
@app.route("/student-add", methods=['POST'])
def confirmation():
"""Confirm student successfully added."""
firstname = request.form.get('firstname')
lastname = request.form.get('lastname')
github = request.form.get('github')
hackbright.make_new_student(firstname, lastname, github)
return render_template("student_add_confirmation.html", firstname=firstname,
lastname=lastname,
github=github)
@app.route("/project/<title>")
def project(title):
"""Show project title, description and maximum grade."""
title, description, maximum_grade = hackbright.get_project_by_title(title)
students_completed_project = hackbright.get_grades_by_title(title) # Assigning list of tuples of students that did the project with their grades.
students = []
for student in students_completed_project:
print "Student: ", student
grade = student[1] # student[1] = row[1] from hackbright.get_grades_by_title
# which is the grade.
print "Grade: ", grade
fname, lname, github = hackbright.get_student_by_github(student[0]) # student[0] = row [0] from hackbright.get_grades_by_title which is the github.
students.append((fname, lname, github, grade))
print "List of tuples: ", students
return render_template("project_info.html", title=title,
description=description,
maximum_grade=maximum_grade)
if __name__ == "__main__":
hackbright.connect_to_db(app)
app.run(debug=True)