Пример #1
0
def delete_teacher():
    db = pymysql.connect(host="localhost",
                         user="******",
                         password="******",
                         db="face_recognition",
                         port=3306,
                         charset='utf8')
    cursor = db.cursor()
    sql = "SELECT t_id FROM teacher"
    cursor.execute(sql)
    t = cursor.fetchall()
    if request.method == "GET":
        return render_template("delete_teacher.html", t=t)
    else:
        teacher_id = request.form.get('teacher_id')
        print(teacher_id)
        sql = "DELETE FROM teacher WHERE t_id='%s'" % teacher_id
        try:
            cursor.execute(sql)
            db.commit()
        except:
            print('error')
            db.rollback()
        db.close()
        message = "删除教师数据成功"
        return render_template("index.html", message=message)
Пример #2
0
 def del_question(que_id):
     try:
         que = Question.query.filter_by(id=que_id).first()
         db.session.delete(que)
         db.session.commit()
         return "ok"
     except Exception as e:
         print(e)
         db.rollback()
         return "fall"
Пример #3
0
def collection():
    if request.method == 'POST':
        #获得文章网址 收藏ok
        xuehao = request.form['xuehao']
        collection = request.form['collection']

        sql_insert = """INSERT INTO collection(xuehao,collection) VALUES ('%s','%s')"""
        try:
            # 执行sql语句
            cursor.execute(sql_insert % (xuehao, collection))
            # 执行sql语句
            db.commit()
            return '收藏成功'
        except:
            # 发生错误时回滚
            db.rollback()

            return 'no'
    else:

        return '404'
Пример #4
0
def insert_teacher():
    message = "提示信息:"
    if request.method == 'GET':
        return render_template('insert_teacher.html', message=message)
    else:
        teacher_name = request.form.get('teacher_name')
        teacher_id = request.form.get('teacher_id')
        teacher_sex = request.form.get('teacher_sex')
        teacher_wx = request.form.get('teacher_wx')
        print(type(teacher_name))
        print(type(teacher_id))
        print(type(teacher_sex))
        print(type(teacher_wx))
        db = pymysql.connect(host="localhost",
                             user="******",
                             password="******",
                             db="face_recognition",
                             port=3306,
                             charset='utf8')
        cursor = db.cursor()
        sql = "SELECT t_id FROM teacher"
        cursor.execute(sql)
        result = cursor.fetchall()
        for i in result:
            print(i[0])
            if i[0] == teacher_id:
                message = message + "该工号教师已存在请重新插入"
                return render_template('insert_teacher.html', message=message)
        sql = "INSERT INTO teacher(t_name,t_id,t_sex,t_wx) VALUES ('%s','%s','%s','%s')" % (
            teacher_name, teacher_id, teacher_sex, teacher_wx)
        try:
            cursor.execute(sql)
            db.commit()
        except:
            db.rollback()
            print("error")
        db.close()
        message = "数据插入成功!"
        return render_template('index.html', message=message)
Пример #5
0
def alter_teacher():
    db = pymysql.connect(host="localhost",
                         user="******",
                         password="******",
                         db="face_recognition",
                         port=3306,
                         charset='utf8')
    cursor = db.cursor()
    sql = "SELECT t_id FROM teacher"
    cursor.execute(sql)
    t = cursor.fetchall()

    if request.method == "GET":
        return render_template("alter_teacher.html", t=t)
    else:
        teacher_id = request.form.get('teacher_id')
        alter_information = request.form.get('alter_information')
        information = request.form.get('information')
        if alter_information == "教师姓名":
            sql = "UPDATE teacher SET t_name='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        elif alter_information == "教师微信id":
            sql = "UPDATE teacher SET t_wx='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        elif alter_information == "教师性别":
            sql = "UPDATE teacher SET t_sex='%s' WHERE t_id='%s'" % (
                information, teacher_id)
        print(sql)
        try:
            cursor.execute(sql)
            db.commit()
        except:
            print('error')
            db.rollback()
        db.close()
        message = "修改教师信息成功"
        return render_template("index.html", message=message)
Пример #6
0
def upload():
    if request.method == 'POST':

        #获取文章,加入数据库
        xuehao = request.form['xuehao']
        title = request.form['title']
        article = request.form['article']
        # SQL 插入语句

        sql_insert = "INSERT INTO opus(xuehao,title,article) VALUES ('%s','%s', '%s')"
        try:
            # 执行sql语句
            cursor.execute(sql_insert % (xuehao, title,article ))
            # 执行sql语句
            db.commit()
            return '上传成功'
        except:
            # 发生错误时回滚
            db.rollback()

            return 'no'
    else:

        return '404'