<commit_before>from flask import Flask, render_template, request
import random
import pymongo
import yaml

app = Flask(__name__)

mongodb_uri = 'mongodb://pomonashuffle:<EMAIL>:33907/pomonashuffle'
db_name = 'pomonashuffle'
connection = pymongo.Connection(mongodb_uri)
db = connection[db_name]

course_col = db.course_col

MAJORS = yaml.load(file('majors.yaml', 'r'))

@app.route('/majors')
def majors():
    return render_template('majors.html', majors=MAJORS)

@app.route('/major/<major>/<number>', methods=['GET', 'POST'])
def ratings(major, number):
    number = int(number)
    if request.method == 'POST':
        # Store the review in the database
        review_text = request.form.get('review', None)
        name = request.form.get('name', None)
        rating = int(request.form['rating'])
        if review_text:
            if not name:
                name = 'Anonymous'

            review = {
                'name': name,
                'text': review_text,
                'major': major,
                'course_number': number,
                'rating': rating
            }

            db.reviews.insert(review)

    reviews = list(db.reviews.find({'major': major, 'course_number': number}))
    course = db.course_col.find({"major": major, "number" : number})
    avg_rating = None
    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')

    if major_code not in MAJORS:
        # Show all the majors
        courses = list(db.course_col.find())
        major = None
        major_code = None
    else:
        courses = list(db.course_col.find({ 'major': major_code }))
        major = MAJORS[major_code]
    return render_template("courses.html", courses=sorted(courses),
            major_code=major_code, major=major)


@app.route('/')<commit_msg>return 303 when posting review<commit_after>from flask import Flask, render_template, request, redirect, url_for
import random
import pymongo
import yaml

app = Flask(__name__)

mongodb_uri = 'mongodb://pomonashuffle:arrokearroke@ds033907.mongolab.com:33907/pomonashuffle'
db_name = 'pomonashuffle'
connection = pymongo.Connection(mongodb_uri)
db = connection[db_name]

course_col = db.course_col

MAJORS = yaml.load(file('majors.yaml', 'r'))

@app.route('/majors')
def majors():
    return render_template('majors.html', majors=MAJORS)

@app.route('/major/<major>/<number>', methods=['GET', 'POST'])
def ratings(major, number):
    number = int(number)
    if request.method == 'POST':
        # Store the review in the database
        review_text = request.form.get('review', None)
        name = request.form.get('name', None)
        rating = int(request.form['rating'])
        if review_text:
            if not name:
                name = 'Anonymous'

            review = {
                'name': name,
                'text': review_text,
                'major': major,
                'course_number': number,
                'rating': rating
            }

            db.reviews.insert(review)
            # Change the request type to GET
            return redirect(url_for('ratings', major=major, number=number), code=303)

    reviews = list(db.reviews.find({'major': major, 'course_number': number}))
    course = db.course_col.find({"major": major, "number" : number})
    avg_rating = None
    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')

    if major_code not in MAJORS:
        # Show all the majors
        courses = list(db.course_col.find())
        major = None
        major_code = None
    else:
        courses = list(db.course_col.find({ 'major': major_code }))
        major = MAJORS[major_code]
    return render_template("courses.html", courses=sorted(courses),
            major_code=major_code, major=major)


@app.route('/')
{'fraction_non_alphanumeric': 0.1331868131868132, 'fraction_numerical': 0.006153846153846154, 'mean_word_length': 2.8147527242246437, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3879730', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1412, 'n_words': 312}