def SubmitComment(homework_id): homework_info = Homework.query.filter_by(homework_id=homework_id).first() homework_info.done = 2 print(request.form) homework_info.comment = request.form['comment'] db_sql.commit() return render_template("index.html")
def toDelTeacher(tea_id): tea_id = int(tea_id) exe = "delete from teacher_info where tea_id = %d" % tea_id cursor.execute(exe) db_sql.commit() url = url_for("admin_page.ShowAllTeachers") return redirect(url)
def mod_pcourse(pcourse_id): if request.method == "POST": update_page_img = 0 print(request.form) file = request.files.get("files") if file.filename: update_page_img = 1 pcourse_id = request.form['pcourse_id'] pcourse_title = request.form['pcourse_title'] pcourse_intro = request.form['pcourse_intro'] pcourse_info = PCourse.query.filter_by(pcourse_id=pcourse_id).first() if update_page_img == 1: # 写的绝对路径,可自己修改 path_static = "F:/test.v0/static/img" imgurl = str(pcourse_info.pcourse_id) + '.jpg' up_path = os.path.join(path_static, imgurl) # 文件保存 file.save(up_path) sql = "update percourse_info set pcourse_imgurl='%s' where pcourse_id=%d" % ( imgurl, pcourse_id) cursor.execute(sql) db_sql.commit() sql = "call p_mod_pcourse(%d,'%s','%s')" % ( pcourse_info.pcourse_id, pcourse_title, pcourse_intro) cursor.execute(sql) db_sql.commit() url = url_for("admin_page.show_pcourses") return redirect(url)
def recharge(): stu_id = session['stu_id'] money = request.form['money'] sql = "call p_stu_recharge('%s',%d)" % (stu_id, int(money)) cursor.execute(sql) db_sql.commit() url = url_for("student_page.show_course") return redirect(url)
def SubmitAns(homework_id): homework_info = Homework.query.filter_by(homework_id=homework_id).first() homework_info.done = 1 file = request.files.get("files") path_static = "F:/test.v0/static/img" imgurl = 'homework' + str(homework_id) + '.jpg' homework_info.store_url = imgurl up_path = os.path.join(path_static, imgurl) file.save(up_path) db_sql.commit() url = url_for("student_page.showinfo") return redirect(url)
def to_buy_pcourse(pcourse_id): stu_id = session['stu_id'] sql = "select(f_get_balance('%s'))" % stu_id cursor.execute(sql) re = cursor.fetchall() stu_balance = re[0][0] if stu_balance < 1: return render_template("recharge.html", stu_balance=stu_balance) sql = "call p_read_percouse(%s,%d)" % (stu_id, int(pcourse_id)) cursor.execute(sql) db_sql.commit() url = url_for("student_page.to_read", pcourse_id=pcourse_id) return redirect(url)
def modTeacher(tea_id): tea_id = int(tea_id) if request.method == 'POST': print(request.form) tea_name = request.form['tea_name'] print(tea_name) tea_email = request.form['tea_email'] password = request.form['password'] teacher_intro = request.form['teacher_intro'] print(tea_name, tea_email, teacher_intro, password) exe = "call p_mod_teacher(%d,'%s','%s','%s','%s')" % ( tea_id, tea_name, tea_email, password, teacher_intro) cursor.execute(exe) db_sql.commit() url = url_for("admin_page.ShowAllTeachers") return redirect(url)
def add_class(): if request.method == 'POST': print(request.form) tea_id = request.form['teacher_id'] scourse_id = request.form['scourse_id'] start_time = request.form['start_time'] end_time = request.form['end_time'] tea_id = int(tea_id) scourse_id = int(scourse_id) sql = "call p_add_class(%d,%d,'%s','%s')" % (tea_id, scourse_id, start_time, end_time) print(sql) cursor.execute(sql) db_sql.commit() url = url_for("admin_page.show_classes") return redirect(url)
def addTeacher(): print(request.method) if request.method == 'POST': print(request.form) tea_name = request.form['tea_name'] print(tea_name) tea_email = request.form['tea_email'] password = request.form['password'] teacher_intro = request.form['teacher_intro'] print(tea_name, tea_email, teacher_intro, password) exe = "call p_add_teacher('%s','%s','%s','%s')" % ( tea_name, tea_email, password, teacher_intro) cursor.execute(exe) db_sql.commit() url = url_for("admin_page.ShowAllTeachers") return redirect(url) return render_template("manageTeacher.html")
def add_course(): if request.method == "POST": print(request.form) scourse_title = request.form['scourse_title'] scourse_theme = request.form['scourse_theme'] scourse_stage = request.form['scourse_stage'] scourse_intro = request.form['scourse_intro'] scourse_credit = request.form['scourse_credit'] scourse_price = request.form['scourse_price'] scourse_theme = 'theme' + scourse_theme scourse_stage = 'stage' + scourse_stage if scourse_credit != '': scourse_credit = int(scourse_credit) else: scourse_credit = 0 if scourse_price != '': scourse_price = float(scourse_price) else: scourse_price = 0 print(scourse_credit, scourse_price) sql = " insert into setcourse_info(scourse_title,scourse_theme,scourse_stage,scourse_intro,scourse_credit,scourse_price)" \ "values('%s','%s','%s','%s',%d,%f)"%(scourse_title,scourse_theme,scourse_stage,scourse_intro,scourse_credit,scourse_price) cursor.execute(sql) db_sql.commit() print(sql) scourse_info = Course.query.filter_by( scourse_title=scourse_title).first() pcourse1 = request.form['pcourse1'] pcourse2 = request.form['pcourse2'] pcourse3 = request.form['pcourse3'] pcourse_id = [pcourse1, pcourse2, pcourse3] temp = [] for i in pcourse_id: print(i) if i not in temp: temp.append(int(i)) pcourse_id = temp for i in pcourse_id: sql = "call p_add_pcourse2scourse(%d,%d)" % ( scourse_info.scourse_id, i) cursor.execute(sql) db_sql.commit() url = url_for("admin_page.show_courses") return redirect(url)
def join_calss(class_id): stu_id = session['stu_id'] sql = "select(f_get_balance('%s'))" % stu_id print(sql) cursor.execute(sql) re = cursor.fetchall() stu_balance = re[0][0] sql = "select scourse_price from stu_class_tea_course where class_id=%d" % int( class_id) print(sql) cursor.execute(sql) re = cursor.fetchall() price = float(re[0][0]) if stu_balance < price: return render_template("recharge.html", stu_balance=stu_balance) sql = "call p_join_class(%s,%d)" % (stu_id, int(class_id)) cursor.execute(sql) db_sql.commit() url = url_for("student_page.showinfo") return redirect(url)
def add_pcourse(): if request.method == "POST": try: file = request.files.get("files") except: print("没传文件") pcourse_title = request.form['pcourse_title'] pcourse_intro = request.form['pcourse_intro'] exe = "insert into percourse_info(pcourse_title,pcourse_intro) values('%s','%s')" % ( pcourse_title, pcourse_intro) cursor.execute(exe) db_sql.commit() pcourse_info = PCourse.query.filter_by( pcourse_title=pcourse_title).first() # 写的绝对路径,可自己修改 path_static = "F:/test.v0/static/img" imgurl = str(pcourse_info.pcourse_id) + '.jpg' up_path = os.path.join(path_static, imgurl) # 文件保存 file.save(up_path) sql = "update percourse_info set pcourse_imgurl='%s' where pcourse_id=%d" % ( imgurl, pcourse_info.pcourse_id) cursor.execute(sql) db_sql.commit() for i in range(1, 4): print(request.form) pro_stem = request.form['pro_stem' + str(i)] pro_num = i flag = request.form['flag' + str(i)] flag = int(flag) exe = "insert into problems(pro_stem,flag,pcourse_id,pro_num) values('%s',%d,%d,%d)" % ( pro_stem, flag, pcourse_info.pcourse_id, i) if (flag == 0): choice = request.form['choice' + str(i)] answer = request.form['ans' + str(i)] exe = "insert into problems(pro_stem,flag,pcourse_id,pro_num,choice,answer) values('%s',%d,%d,%d,'%s','%s')" % ( pro_stem, flag, pcourse_info.pcourse_id, i, choice, answer) cursor.execute(exe) db_sql.commit() url = url_for("admin_page.show_pcourses") return redirect(url)
def del_calss(class_id): sql = "delete from class_info where class_id=%d" % int(class_id) cursor.execute(sql) db_sql.commit() url = url_for("admin_page.show_classes") return redirect(url)