<commit_before>from flask_restful import Resource, reqparse, abort
from flask.ext.login import current_user, login_required

from server.models import db, Course, Lecturer


class CourseListResource(Resource):
    def get(self):
        argparser = reqparse.RequestParser()
        argparser.add_argument('lecturer', location='args', type=int)
        args = argparser.parse_args()

        query = (
            db.session.query(
                Course.id,
                Course.name
            )
        )

        if args.lecturer is not None:
            query = query.filter(Course.lecturer_id == args.lecturer)

        return [
            {
                'id': row.id,
                'name': row.name
            }
            for row in query
        ]

    @login_required
    def post(self):
        argparser = reqparse.RequestParser()
        argparser.add_argument('name', required=True)
        argparser.add_argument('lecturerId', type=int, required=True)
        args = argparser.parse_args()

        if args.lecturerId != current_user.id:
            abort(403, message="lectureId must be the ID og the logged in lecturer")

        lecturer = Lecturer.query.filter(Lecturer.id == args.lecturerId).first()

        course = Course(args.name, lecturer)
        db.session.add(course)
        db.session.commit()
<commit_msg>Fix typo<commit_after>from flask_restful import Resource, reqparse, abort
from flask.ext.login import current_user, login_required

from server.models import db, Course, Lecturer


class CourseListResource(Resource):
    def get(self):
        argparser = reqparse.RequestParser()
        argparser.add_argument('lecturer', location='args', type=int)
        args = argparser.parse_args()

        query = (
            db.session.query(
                Course.id,
                Course.name
            )
        )

        if args.lecturer is not None:
            query = query.filter(Course.lecturer_id == args.lecturer)

        return [
            {
                'id': row.id,
                'name': row.name
            }
            for row in query
        ]

    @login_required
    def post(self):
        argparser = reqparse.RequestParser()
        argparser.add_argument('name', required=True)
        argparser.add_argument('lecturerId', type=int, required=True)
        args = argparser.parse_args()

        if args.lecturerId != current_user.id:
            abort(403, message="lectureId must be the ID of the logged in lecturer")

        lecturer = Lecturer.query.filter(Lecturer.id == args.lecturerId).first()

        course = Course(args.name, lecturer)
        db.session.add(course)
        db.session.commit()

{'fraction_non_alphanumeric': 0.09892153216809223, 'fraction_numerical': 0.002231312755671253, 'mean_word_length': 2.0568181818181817, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '1424933', 'n_tokens_mistral': 779, 'n_tokens_neox': 742, 'n_words': 167}