示例#1
0
def show(id):
    thread = Thread.get_or_none(Thread.id == id)

    if thread:
        return jsonify({
            'id': thread.id,
            'template': thread.template,
            'content': thread.content
        }), 200
    else:
        return jsonify({'message': 'thread not found'}), 418
示例#2
0
def upload(user_id, course_title, post_id):
    user = User.get_or_none(User.id == user_id)
    course = Course.get_or_none(Course.title == course_title)
    thread = Thread.get_or_none(Thread.course_id == course.id)

    post =  Post.get_or_none(Post.file_path != 'NULL', Post.thread_id == thread.id)
    
    params = request.form

    title = params.get("title")

    info = StudentCourse.get_or_none(StudentCourse.student_id == user_id, StudentCourse.course_name_id == course.id)
    
    if info:
        if current_user.id == user.id:
            # We check the request.files object for a user_file key. (user_file is the name of the file input on our form). If it's not there, we return an error message.
            if "assignment" not in request.files:
                flash("No file provided!", "danger")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
            
            # If the key is in the object, we save it in a variable called file.
            file = request.files["assignment"]

            # we sanitize the filename using the secure_filename helper function provided by the werkzeurg.security module.
            # file.filename = secure_filename(file.filename)

            # get path to image on S3 bucket using function in helper.py
            file_path = upload_file_to_s3(file, user.username)
            
            new_assignment = Assignment(title=title, info_id=info.id, file_path=file_path, post_id=post.id)
            
            if new_assignment.save():
                flash("Successfully uploaded!","success")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))  # then redirect to profile page
            else:
                flash("Upload failed. Please try again!", "danger")
                return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
        else:
            flash("Cannot upload assignments for other users", "danger")
            return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
            
    else:
        flash("Failed to upload!", "danger")
        return redirect(url_for('posts.show', course_name=course_title, user_id=current_user.id, post_id = post.id))
示例#3
0
def upload(thread_id):
    # if not 'image' in request.files:

    #     return jsonify({'msg': 'no image given'}), 400

    file = request.files.get('image')

    file.filename = secure_filename(file.filename)

    if not upload_file_to_s3(file):
        return jsonify({'msg': 'upload to s3 failed'}), 400

    thread = Thread.get_or_none(Thread.id == thread_id)
    thread.template = file.filename
    # thread = Thread(template=file.filname)
    thread.save()

    # os.remove(temp_storage)

    return jsonify({'msg': 'upload to s3 success'}), 200
示例#4
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"