forked from bton/matekasse
added a function to transfare money between two user
This commit is contained in:
parent
cfafd0e148
commit
3c87a971ea
3 changed files with 59 additions and 0 deletions
|
@ -283,6 +283,31 @@ def create_app(test_config=None):
|
||||||
socketio.emit("error", "418", to=session[id])
|
socketio.emit("error", "418", to=session[id])
|
||||||
leave_room(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'])
|
@app.route("/api/balance", methods=['POST', 'GET'])
|
||||||
def api_change():
|
def api_change():
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
| <a href="/list">user and tag list</a>
|
| <a href="/list">user and tag list</a>
|
||||||
| <a href="/documentation">Documentation</a>
|
| <a href="/documentation">Documentation</a>
|
||||||
| <a href="/transactionlist">transactionlist</a>
|
| <a href="/transactionlist">transactionlist</a>
|
||||||
|
| <a href="/transfare">transfare</a>
|
||||||
</p>
|
</p>
|
||||||
</nav>
|
</nav>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
33
Website/templates/transfare.html
Normal file
33
Website/templates/transfare.html
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
transfare
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<form action="/api/transfare" method="post">
|
||||||
|
<p>
|
||||||
|
<select name="transfarefrom">
|
||||||
|
<option value="">Select the user to transfare from</option>
|
||||||
|
{% for user in user_list %}
|
||||||
|
<option value={{user[0]}}>{{user[1]}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<select name="transfareto">
|
||||||
|
<option value="">Select the user to transfare to</option>
|
||||||
|
{% for user in user_list %}
|
||||||
|
<option value={{user[0]}}>{{user[1]}}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input name="change" type="number" lang="nb" step="0.01" max=1000 min=-1000 placeholder="money to transfare">
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<button type="submit">transfare money</button>
|
||||||
|
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue