forked from bton/matekasse
transaction list as template
This commit is contained in:
parent
a31337f0f2
commit
efff31aa27
1 changed files with 40 additions and 38 deletions
|
@ -69,49 +69,51 @@ def create_app(test_config=None):
|
|||
def transactionlist():
|
||||
db = get_db()
|
||||
c = db.cursor()
|
||||
text = ""
|
||||
action_list = []
|
||||
c.execute("SELECT * FROM transaction_log ORDER BY ROWID DESC LIMIT 1000")
|
||||
transactionlist = c.fetchall()
|
||||
for i in transactionlist:
|
||||
statement = i[0]
|
||||
user_id = i[1]
|
||||
before = i[2]
|
||||
after = i[3]
|
||||
change = i[4]
|
||||
if statement == "balance":
|
||||
reverse_statement = "balance"
|
||||
reverse_user_id = user_id
|
||||
reverse_before = None
|
||||
reverse_after = None
|
||||
reverse_change = change *(-1)
|
||||
elif statement == "add_user":
|
||||
reverse_statement = "remove_user"
|
||||
reverse_user_id = user_id
|
||||
reverse_before = after
|
||||
reverse_after = None
|
||||
reverse_change = None
|
||||
elif statement == "remove_user":
|
||||
reverse_statement = "add_user"
|
||||
reverse_user_id = user_id
|
||||
reverse_before = None
|
||||
reverse_after = before
|
||||
reverse_change = None
|
||||
elif statement == "add_tag":
|
||||
reverse_statement = "remove_tag"
|
||||
reverse_user_id = user_id
|
||||
reverse_before = after
|
||||
reverse_after = None
|
||||
reverse_change = None
|
||||
elif statement == "remove_tag":
|
||||
reverse_statement = "add_tag"
|
||||
reverse_user_id = user_id
|
||||
reverse_before = None
|
||||
reverse_after = before
|
||||
reverse_change = None
|
||||
action = {
|
||||
"statement":i[0],
|
||||
"user_id":i[1],
|
||||
"before":i[2],
|
||||
"after":i[3],
|
||||
"change":i[4]
|
||||
}
|
||||
if action["statement"] == "balance":
|
||||
action["reverse_statement"] = "balance"
|
||||
action["reverse_user_id"] = action["user_id"]
|
||||
action["reverse_before"] = None
|
||||
action["reverse_after"] = None
|
||||
action["reverse_change"] = action["change"] *(-1)
|
||||
elif action["statement"] == "add_user":
|
||||
action["reverse_statement"] = "remove_user"
|
||||
action["reverse_user_id"] = action["user_id"]
|
||||
action["reverse_before"] = action["after"]
|
||||
action["reverse_after"] = None
|
||||
action["reverse_change"] = None
|
||||
elif action["statement"] == "remove_user":
|
||||
action["reverse_statement"] = "add_user"
|
||||
action["reverse_user_id"] = action["user_id"]
|
||||
action["reverse_before"] = None
|
||||
action["reverse_after"] = action["before"]
|
||||
action["reverse_change"] = None
|
||||
elif action["statement"] == "add_tag":
|
||||
action["reverse_statement"] = "remove_tag"
|
||||
action["reverse_user_id"] = action["user_id"]
|
||||
action["reverse_before"] = action["after"]
|
||||
action["reverse_after"] = None
|
||||
action["reverse_change"] = None
|
||||
elif action["statement"] == "remove_tag":
|
||||
action["reverse_statement"] = "add_tag"
|
||||
action["reverse_user_id"] = action["user_id"]
|
||||
action["reverse_before"] = None
|
||||
action["reverse_after"] = action["before"]
|
||||
action["reverse_change"] = None
|
||||
else:
|
||||
raise Exception(statement)
|
||||
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
|
||||
action_list.append(action)
|
||||
return render_template("transactionlist.html", action_list=action_list)
|
||||
|
||||
@app.route("/list/user", methods=['GET'])
|
||||
def user_info():
|
||||
|
|
Loading…
Reference in a new issue