def getcourse_list(): cookies = request.cookies if not 'session' in cookies: return jsonify(res=PARAMETER_WRONG) session = cookies['session'] # session = '111111' from lib import get_userid_by_session userid = get_userid_by_session(session) if userid == None: return jsonify(res=USER_NOT_LOGIN_IN) from lib import check_user_is_teacher res = check_user_is_teacher(userid) from lib import get_course_by_userid course_list = get_course_by_userid(userid, res) return jsonify(res=SUCCESS, course=course_list)
def course_teacher_info(courseid): cookies = request.cookies if not 'session' in cookies: return jsonify(res=PARAMETER_WRONG) session = cookies['session'] from lib import get_userid_by_session userid = get_userid_by_session(session) if userid == None: return jsonify(res=USER_NOT_LOGIN_IN) from lib import check_user_is_teacher isteacher = check_user_is_teacher(userid) from lib import check_attend_course res = check_attend_course(userid, courseid, isteacher) if res == False: return jsonify(res=PERMISSION_DENIED) from lib import get_course_teacher_info_by_courseid teacher = get_course_teacher_info_by_courseid(courseid) return jsonify(res=SUCCESS, teacher=teacher)
def downloads(courseid): cookies = request.cookies if 'session' in cookies: session = cookies['session'] from lib import get_userid_by_session userid = get_userid_by_session(session) if userid == None: return redirect('/login') else: from lib import check_user_is_teacher isteacher = check_user_is_teacher(userid) from lib import check_attend_course res = check_attend_course(userid, courseid, isteacher) if res == False: return jsonify(res=PERMISSION_DENIED) if isteacher: return render_template('downloads_teacher.html', courseid=courseid) else: return render_template('downloads.html', courseid=courseid) else: return redirect('/login')
def course_add(): cookies = request.cookies if not 'session' in cookies: return jsonify(res=PARAMETER_WRONG) session = cookies['session'] from lib import get_userid_by_session userid = get_userid_by_session(session) if userid == None: return jsonify(USER_NOT_LOGIN_IN) from lib import check_user_is_teacher res = check_user_is_teacher(userid) if res == False: return jsonify(res=PERMISSION_DENIED) form = request.form require = ['name', 'description', 'time', 'classroom'] for item in require: if not item in form: return jsonify(res=PARAMETER_WRONG) name = form['name'] description = form['description'] time = form['time'] classroom = form['classroom'] from lib import get_name_by_userid teacher = get_name_by_userid(userid) teacher = teacher.decode('utf-8') files = request.files f = files['file'] filename = f.filename f.save('tmp/' + filename) from lib import add_course add_course(teacher, name, description, time, classroom, filename) return jsonify(res=SUCCESS)