コード例 #1
0
def check(course_title, user_id, post_id):
    current_course = Course.get_or_none(Course.title == course_title)
    current_info = StudentCourse.get_or_none(StudentCourse.course_name_id == current_course.id)
    current_assignment = Assignment.get_or_none(Assignment.post_id == post_id, Assignment.info_id == current_info.id)

    params = request.form

    current_assignment.title = current_assignment.title
    current_assignment.info_id = current_assignment.info_id
    current_assignment.file_path = current_assignment.file_path
    current_assignment.post_id = current_assignment.post_id

    current_assignment.grade_id = params.get('grade')

    if current_assignment.save():
        flash("Successfully graded the student!")
        return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post_id))
    else:
        flash("Failed to grade the student!")
        return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post_id))
コード例 #2
0
def show(course_name, user_id, post_id):
    user = User.get_or_none(User.id == user_id)
    current_course = Course.get_or_none(Course.title == course_name)
    thread = Thread.get_or_none(Thread.course_id == current_course.id)

    if user.role.role == 'Teacher':
        submitted_assignments = []
        for assignment in Assignment.select().where(Assignment.post_id == post_id):
            submitted_assignments.append(assignment)

    if user.role.role == 'Student':
        info = StudentCourse.get_or_none(StudentCourse.student_id == user.id, StudentCourse.course_name_id == current_course.id)
        submitted_assignments = Assignment.get_or_none(Assignment.info_id == info.id)

    assignment_post = []
    week_num = []
    i = 1

    for post in Post.select().where(Post.thread_id == thread.id):
        if post.file_path:
            assignment_post.append(post)
            week_num.append(i)

            i += 1

    grades = []
    for grade in Grade.select():
        grades.append(grade)


    assignment_week = dict(zip(week_num, assignment_post))
    print(str(assignment_week))

    # for assignment in Assignment.select().where()
    

    return render_template('posts/show.html', course_title=course_name, user_id=user_id, post_id=post_id, assignment_week=assignment_week, submitted_assignments=submitted_assignments, grades=grades)
        
    # is_student= user.role == "student"