From 3c87a971eaf317a220bfca36e035a0fc4388ea19 Mon Sep 17 00:00:00 2001 From: bton Date: Wed, 18 Sep 2024 22:25:50 +0200 Subject: [PATCH 1/3] added a function to transfare money between two user --- Website/__init__.py | 25 ++++++++++++++++++++++++ Website/templates/base.html | 1 + Website/templates/transfare.html | 33 ++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 Website/templates/transfare.html diff --git a/Website/__init__.py b/Website/__init__.py index 307dace..d942b8e 100644 --- a/Website/__init__.py +++ b/Website/__init__.py @@ -283,6 +283,31 @@ def create_app(test_config=None): socketio.emit("error", "418", to=session[id]) leave_room(session[id]) + @app.route("/transfare") + def transfare(): + db = get_db() + c = db.cursor() + c.execute("SELECT * FROM users") + user_list = c.fetchall() + return render_template("transfare.html", user_list=user_list) + + @app.route("/api/transfare", methods=['POST']) + def api_transfare(): + db = get_db() + c = db.cursor() + transfare_from = request.form["transfarefrom"] + transfare_to = request.form["transfareto"] + change = int(request.form["change"]) * 100 + c.execute("SELECT * FROM users WHERE id=?", [transfare_from]) + if c.fetchall() == []: + return render_template("error.html", error_code="043") + c.execute("SELECT * FROM users WHERE id=?", [transfare_to]) + if c.fetchall() == []: + return render_template("error.html", error_code="043") + db_handler.change_balance(transfare_from, -change) + db_handler.change_balance(transfare_to, change) + return render_template("redirect.html") + @app.route("/api/balance", methods=['POST', 'GET']) def api_change(): if request.method == 'POST': diff --git a/Website/templates/base.html b/Website/templates/base.html index 69fdd57..cb34bcc 100644 --- a/Website/templates/base.html +++ b/Website/templates/base.html @@ -17,6 +17,7 @@ | user and tag list | Documentation | transactionlist + | transfare


diff --git a/Website/templates/transfare.html b/Website/templates/transfare.html new file mode 100644 index 0000000..22c1c73 --- /dev/null +++ b/Website/templates/transfare.html @@ -0,0 +1,33 @@ +{% extends "base.html" %} + +{% block title %} + transfare +{% endblock %} +{% block content %} +
+

+ +

+

+ +

+

+ +

+

+ + +

+
+{% endblock %} + From 379f8b1fd3af8c24cc6e64a44f0b6f78b74bc9ac Mon Sep 17 00:00:00 2001 From: bton Date: Wed, 18 Sep 2024 22:29:02 +0200 Subject: [PATCH 2/3] changed a float error --- Website/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Website/__init__.py b/Website/__init__.py index d942b8e..dd06e73 100644 --- a/Website/__init__.py +++ b/Website/__init__.py @@ -297,7 +297,7 @@ def create_app(test_config=None): c = db.cursor() transfare_from = request.form["transfarefrom"] transfare_to = request.form["transfareto"] - change = int(request.form["change"]) * 100 + change = int(float(request.form["change"]) * float(100)) c.execute("SELECT * FROM users WHERE id=?", [transfare_from]) if c.fetchall() == []: return render_template("error.html", error_code="043") From 2357d37228b08df4f7bfc0ba3d71890c929d57e1 Mon Sep 17 00:00:00 2001 From: bton Date: Wed, 18 Sep 2024 22:32:25 +0200 Subject: [PATCH 3/3] changed smth? --- Website/templates/transfare.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Website/templates/transfare.html b/Website/templates/transfare.html index 22c1c73..d5425ba 100644 --- a/Website/templates/transfare.html +++ b/Website/templates/transfare.html @@ -22,7 +22,8 @@

- + +