1
0
Fork 0
forked from bton/matekasse

Transaction log without time

This commit is contained in:
bton 2024-03-19 23:52:49 +01:00
parent e76e5beae7
commit dd9e3463c9
3 changed files with 7 additions and 8 deletions

View file

@ -73,11 +73,11 @@ def create_app(test_config=None):
c.execute("SELECT * FROM transaction_log ORDER BY ROWID DESC LIMIT 1000") c.execute("SELECT * FROM transaction_log ORDER BY ROWID DESC LIMIT 1000")
transactionlist = c.fetchall() transactionlist = c.fetchall()
for i in transactionlist: for i in transactionlist:
statement = i[1] statement = i[0]
user_id = i[2] user_id = i[1]
before = i[3] before = i[2]
after = i[4] after = i[3]
change = i[5] change = i[4]
if statement == "balance": if statement == "balance":
reverse_statement = "balance" reverse_statement = "balance"
reverse_user_id = user_id reverse_user_id = user_id
@ -110,7 +110,7 @@ def create_app(test_config=None):
reverse_change = None reverse_change = None
else: else:
raise Exception(statement) raise Exception(statement)
text = text + f'<form action="/api/change" method="post"><p style="display: inline;">{i[0]} {statement} userid:{user_id} {before} {after} {change}</p><input type="hidden" name="statement" value={reverse_statement}><input type="hidden" name="user_id" value={reverse_user_id}><input type="hidden" name="before" value={reverse_before}><input type="hidden" name="after" value={reverse_after}><input type="hidden" name="change" value={reverse_change}><button type="submit">rollback</button></form><br></br>' text = text + f'<form action="/api/change" method="post"><p style="display: inline;">{statement} userid:{user_id} {before} {after} {change}</p><input type="hidden" name="statement" value={reverse_statement}><input type="hidden" name="user_id" value={reverse_user_id}><input type="hidden" name="before" value={reverse_before}><input type="hidden" name="after" value={reverse_after}><input type="hidden" name="change" value={reverse_change}><button type="submit">rollback</button></form><br></br>'
return text return text
@app.route("/list/user", methods=['GET']) @app.route("/list/user", methods=['GET'])

View file

@ -8,7 +8,7 @@ from flask import current_app, g
def log(statement, user_id=None, before=None, after=None, change=None): def log(statement, user_id=None, before=None, after=None, change=None):
db = get_db() db = get_db()
c = db.cursor() c = db.cursor()
c.execute("INSERT INTO transaction_log (timestamp, type, user_id, before, after, change) VALUES (?, ?, ?, ?, ?, ?)", [datetime.now(), statement, user_id, before, after, change]) c.execute("INSERT INTO transaction_log (type, user_id, before, after, change) VALUES (?, ?, ?, ?, ?)", [ statement, user_id, before, after, change])
db.commit() db.commit()
def add_user(after): def add_user(after):

View file

@ -12,7 +12,6 @@ CREATE TABLE IF NOT EXISTS "tags" (
PRIMARY KEY("tagid") PRIMARY KEY("tagid")
); );
CREATE TABLE IF NOT EXISTS "transaction_log" ( CREATE TABLE IF NOT EXISTS "transaction_log" (
"timestamp" INTEGER NOT NULL,
"type" TEXT NOT NULL, "type" TEXT NOT NULL,
"user_id" INTEGER, "user_id" INTEGER,
"before" TEXT, "before" TEXT,