Esempio n. 1
0
def assignment(id):
    assignment = get_assignment(id)
    course = get_course(assignment['course_id'])

    if g.user['role'] == 'teacher':
        with db.get_db() as con:
            with con.cursor() as cur:
                cur.execute("""
                    SELECT s.*,
                           u.name
                    FROM submissions AS s
                    JOIN users AS u ON u.id = s.student_id
                    WHERE s.assignment_id = %s""", (assignment['id'],))
                submissions = cur.fetchall()

        return render_template('assignments/list.html', assignment=assignment, course=course, submissions=submissions)

    elif g.user['role'] == 'student':
        with db.get_db() as con:
            with con.cursor() as cur:
                cur.execute("SELECT * FROM submissions WHERE assignment_id = %s AND student_id = %s", (id, g.user['id'],))
                submission = cur.fetchone()

        return render_template('assignments/list.html', assignment=assignment, course=course, submission=submission)

    else:
        abort(401)
Esempio n. 2
0
def grade_book(session_id, course_id):
    session = sessions.get_session(session_id)
    course = courses.get_course(course_id)
    assignments = assign.get_assignment(session_id, True)
    for assignment in assignments:
        with db.get_db() as con:
            with con.cursor() as cur:
                cur.execute(
                    'SELECT * FROM submissions WHERE student_id = %s AND assignment_id = %s',
                    (
                        g.user['id'],
                        assignment['id'],
                    ))

                if cur.fetchone() == None:
                    cur.execute(
                        """INSERT INTO submissions (assignment_id, student_id)
                            VALUES (%s, %s)""", (
                            assignment['id'],
                            g.user['id'],
                        ))

    submissions = get_submissions(session_id)
    """Allows student to veiw grades for a course"""
    if session['course_id'] != course['course_num']:
        abort(403)

    for submission in submissions:
        if submission['grade'] == None:
            submission['grade'] = 0

    return render_template("student_views/grade_book.html",
                           course=course,
                           session=session,
                           submissions=submissions)
Esempio n. 3
0
def create_assignment(id):
    course = get_course(id)
    if g.user['role'] == 'teacher':
        if request.method == 'POST':
            assignment_name = request.form['assignment_name']
            assignment_description =  request.form['assignment_description']
            type = request.form['type']
            points = request.form['total_points']

            with db.get_db() as con:
                with con.cursor() as cur:
                    cur.execute(
                        'INSERT INTO assignments (assignment_name, assignment_description, course_id, type, total_points)'
                        'VALUES (%s, %s, %s, %s, %s)'
                        'RETURNING id;',
                        (assignment_name, assignment_description, course['id'], type, points))
                    assignment_added = cur.fetchone()[0]
                    course_sessions = get_sessions(id)
                    for session in course_sessions:
                        cur.execute("SELECT student_id FROM user_sessions WHERE session_id = %s", (session['id'],))
                        students = cur.fetchall()
                    for student in students:
                        cur.execute(
                            'INSERT INTO submissions (points_scored, feedback, graded, assignment_id, student_id)'
                            'VALUES (null, null, %s, %s, %s);',
                            (False, assignment_added, student[0]))

            return redirect(url_for('courses.course', id=id))

        return render_template('assignments/create.html')

    else:
        abort(401)
Esempio n. 4
0
def index(id):
    course = get_course(id)
    user = get_user(id)
    con = get_db()
    cur = con.cursor(cursor_factory=DictCursor)
    cur.execute("SELECT * FROM assignments WHERE course_id = %s", (id, ))
    assignments = cur.fetchall()
    cur.close()

    return render_template('/assignments/index.html',
                           assignments=assignments,
                           user=user,
                           course=course)
Esempio n. 5
0
def assign_view(assign_id, session_id, course_id):
    """Allows students to view a specific assignment's details for a specific course"""
    assignment = assign.get_assignment(assign_id)
    session = sessions.get_session(session_id)
    course = courses.get_course(course_id)
    if session['course_id'] != course['course_num']:
        abort(403)
    if session['id'] != assignment['sessions_id']:
        abort(403)

    return render_template("student_views/assignment_details.html",
                           session=session,
                           assignment=assignment,
                           course=course)
Esempio n. 6
0
def session_assignments(session_id, course_id):
    """Allows students to view their assignments for a specific course"""
    session = sessions.get_session(session_id)
    course = courses.get_course(course_id)

    if session['course_id'] != course['course_num']:
        abort(403)

    cur = db.get_db().cursor()

    cur.execute(
        """
            SELECT * FROM assignments
            WHERE sessions_id = %s""", (session_id, ))

    assignments = cur.fetchall()

    cur.close()
    return render_template("student_views/your_assignments.html",
                           session=session,
                           assignments=assignments,
                           course=course)
Esempio n. 7
0
def create(id):
    course = get_course(id)

    if request.method == 'POST':
        name = request.form['name']
        due_date = request.form['due_date']
        description = request.form['description']
        points = request.form['points']

        if name == '' or due_date == '' or description == '' or points == '':
            return redirect(url_for('assignments.index'))

        con = get_db()
        cur = con.cursor()
        cur.execute(
            "INSERT INTO assignments (name, due_date, description, points, course_id) VALUES (%s, %s, %s, %s, %s)",
            (name, due_date, description, points, id))
        con.commit()
        cur.close()

        flash('Success!')
        return redirect(url_for('courses.index'))

    return render_template('assignments/create.html', course=course)
Esempio n. 8
0
def all_grades(course_id, sessions_id):
    """Teachers can view all of their students total
    grades with in a class session"""
    course = courses.get_course(course_id)
    session = sessions.get_session(sessions_id)
    students = get_students(sessions_id)
    # Holds all total grades
    total_student_grades = []

    # Security checks
    if g.user['id'] != course['teacher_id']:
        abort(403)

    if course['course_num'] != session['course_id']:
        abort(403)

    for student in students:
        # default of zero
        points = 0
        grades = 0

        with db.get_db() as con:
            with con.cursor() as cur:

            # Getting each assignment data
                cur.execute(
                """SELECT assign_name, id, points
                FROM assignments WHERE sessions_id = %s""",
                (student['id'], )
                )
                # all assignments per student
                assignments = cur.fetchall()
                for assignment in assignments:

                    if assignment['points'] != None:
                        points += assignment['points']


                cur.execute(
                """SELECT grade, assignment_id, student_id FROM Submissions
                WHERE student_id = %s""",
                (student['user_id'], )
                )

                student_submissions = cur.fetchall()



                for submission in student_submissions:


                    if submission['grade'] != None:
                        grades += submission['grade']


                total_student_grade = submissions.letter_grade(grades, points)
                # adding each student total grade to the list

                grade_and_name = (total_student_grade, student['name'])

                total_student_grades.append(grade_and_name)


    return render_template("teacher_views/allGrades.html", course=course, session=session, letter_grade=total_student_grades, students=students)
Esempio n. 9
0
def assign_grade(course_id, sessions_id, assign_id):
    """Allows teachers to see a grade and point score
    for each student for each assignment in a course session"""

    course = courses.get_course(course_id)
    session = sessions.get_session(sessions_id)
    students = get_students(sessions_id)
    assignment = assign.get_assignment(assign_id)
    students_assign_grade = []


    # Security Checks
    if g.user['id'] != course['teacher_id']:
        abort(403)

    if course['course_num'] != session['course_id']:
        abort(403)

    if session['id'] != assignment['sessions_id']:
        abort(403)

    # Getting database connection
    with db.get_db() as con:
        with con.cursor() as cur:

            # Getting each assignment data
            cur.execute(
            """SELECT assign_name, id, points, description
            FROM assignments WHERE sessions_id = %s AND id = %s""",
            (assignment['sessions_id'], assign_id,)
            )
            # all assignments per student
            assignment = cur.fetchone()

            for student in students:
                # default of zero
                points = 0
                grades = 0


                # All grades per student's assignment
                cur.execute("""
                    SELECT grade FROM submissions
                    WHERE student_id = %s AND assignment_id = %s""",
                    (student['user_id'], assign_id,))

                student_submission = cur.fetchone()

                

                # If there is no submission, set a default grade of zero
                for submission_of_student in student_submission:

                    if submission_of_student == None:
                        submission_of_student = 0


                    if submission_of_student != None:

                        #Get letter grade of student for assignment
                        letter_grade = submissions.letter_grade(submission_of_student, assignment['points'])
                        #Set tuple equal to var so values can be iterated properly
                        one_assignment_grade = (student['name'], submission_of_student, letter_grade)
                        # Adding submission to list
                        students_assign_grade.append(one_assignment_grade)



    return render_template('teacher_views/assign_grades.html', students=students, session=session, assignment=assignment, assignment_grade=students_assign_grade)