Esempio 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})
Esempio 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})
Esempio n. 3
0
def getlist():
    cur = DictCursor(mysql.get_db())
    cur.execute("SELECT * FROM attend;")
    return jsonify(cur.fetchall())
Esempio n. 4
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)