-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py~
executable file
·59 lines (40 loc) · 1.56 KB
/
app.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
from flask import Flask, render_template, request, redirect, url_for
import pymongo
import yaml
app = Flask(__name__)
mongodb_uri = 'mongodb://pomonashuffle:[email protected]:33907/pomonashuffle'
db_name = 'pomonashuffle'
connection = pymongo.Connection(mongodb_uri)
MAJORS = yaml.load(file('majors.yaml', 'r'))
@app.route('/majors')
def majors():
return render_template('majors.html', majors=MAJORS)
@app.route('/major/<major>/<int:number>', methods=['GET', 'POST'])
def ratings(major, number):
if request.method == 'POST':
# Store the review in the database
# Change the request type to GET
#find the reviews
avg_rating = None
#Once we have the reviews fimd the average rating for the course
if reviews:
ratings_sum = sum([r.get('rating', 0) for r in reviews])
avg_rating = float(ratings_sum) / len(reviews)
avg_rating = round(avg_rating, 2)
course = course[0]
return render_template("ratings.html", course=course, avg_rating=avg_rating,
reviews=reviews)
@app.route('/courses')
def classes_for_major():
major_code = request.args.get('major', 'any')
school = request.args.get('school', 'any')
major = None
filter_doc = {}
#get a listed of the courses offered by name and
return render_template("courses.html", courses=courses,
major_code=major_code, major=major)
@app.route('/')
def index():
return render_template('index.html', courses=courses, majors=MAJORS)
if __name__ == '__main__':
app.run(debug=True)