Ejemplo n.º 1
0
def checkin():
    cid = request.form.get("id")
    if cid:
        conn = mysql.get_db()
        cur = DictCursor(conn)
        varlist = ""
        val_tuple = ()
        for item in request.form:
            if item.startswith("input_"):
                varlist += "," + item.replace("input_", "") + "=%s"
                val_tuple += (request.form[item], )
        val_tuple += (
            request.form.get("fp"),
            cid,
        )
        cur.execute(
            "UPDATE attend SET attendance=1" + varlist + ",fp=%s WHERE id=%s;",
            val_tuple)
        conn.commit()
        if cur.rowcount == 1:
            return jsonify({"ret": 1})
        else:
            return jsonify({"ret": -1})
    else:
        return jsonify({"ret": -1})
Ejemplo n.º 2
0
def info():
    stu_name = request.form.get("stu_name")
    fp = request.form.get("fp")
    if stu_name and fp:
        result = {}
        cur = DictCursor(mysql.get_db())
        cur.execute("SELECT COUNT(*) AS c FROM attend WHERE fp=%s;", fp)
        if cur.fetchone()["c"] > 0:
            return jsonify({"ret": -2})
        cur.execute("SELECT * FROM attend WHERE stu_name=%s;", stu_name)
        data = cur.fetchone()
        col_config = get_column_config()
        if data:
            del data["fp"]
            result["id"] = data.pop("id")
            result["attendance"] = data.pop("attendance")
            new_data = {}
            for item in data:
                if isinstance(data[item], str):
                    data[item] = data[item].strip()
                    if col_config[item] == 0:
                        data[item] = data[item].replace("\n", "<br/>")
                        if not data[item]:
                            data[item] = "无"
                if col_config[item] == 1:
                    new_data["input_" + item] = data[item]
                else:
                    new_data[item] = data[item]
            result["data"] = new_data
            result["ret"] = 1
        else:
            result["ret"] = -1
        return jsonify(result)
    else:
        return jsonify({"ret": -1})
Ejemplo n.º 3
0
# try:
#     with DictCursor(connection) as cursor:
#         # 执行sql语句,进行查询
#         sql = 'SELECT nav_id,nav_text from navbar where nav_id = 1'
#         cursor.execute(sql)
#         # 获取查询结果
#         result = cursor.fetchone()
#         print(result)
#     # 没有设置默认自动提交,需要主动提交,以保存所执行的语句
#     connection.commit()
#
# finally:
#     connection.close();

try:
    with DictCursor(connection) as cursor:
        # 执行sql语句,进行查询
        sql = 'INSERT INTO navbar (nav_text,nav_url,nav_order)VALUES(%(text)s,%(url)s,%(order)s)'
        cursor.execute(sql, {
            "text": "python",
            "url": "/python",
            "order": "10"
        })
        # 获取查询结果
        # result = cursor.fetchone()
        # print(result)
    # 没有设置默认自动提交,需要主动提交,以保存所执行的语句
    connection.commit()

finally:
    connection.close()
Ejemplo n.º 4
0
 def record_callback_fetch_value(cursor: DictCursor, field=None):
     row = cursor.fetchone()
     return list(row.values())[0] if field is None else row.get(field)
Ejemplo n.º 5
0
 def record_callback_fetch_one(cursor: DictCursor):
     return cursor.fetchone()
Ejemplo n.º 6
0
 def record_callback_fetch_all(cursor: DictCursor):
     return cursor.fetchall()
Ejemplo n.º 7
0
def getlist():
    cur = DictCursor(mysql.get_db())
    cur.execute("SELECT * FROM attend;")
    return jsonify(cur.fetchall())
Ejemplo n.º 8
0
def getpayment():
    cur = DictCursor(mysql.get_db())
    cur.execute(
        "SELECT id,stu_name,stu_unit,price FROM attend WHERE paid=0 AND attendance=1;"
    )
    return dumps(cur.fetchall(), ensure_ascii=False)