forked from bton/matekasse
jinja
This commit is contained in:
parent
2432eed1ae
commit
5179ec792c
8 changed files with 128 additions and 91 deletions
|
@ -1,5 +1,5 @@
|
||||||
import queue, time, uuid, json, logging, datetime, os
|
import queue, time, uuid, json, logging, datetime, os
|
||||||
from flask import Flask, render_template, request, make_response, session, send_file, g
|
from flask import Flask, render_template, render_template_string, request, make_response, session, send_file, g
|
||||||
from flask_socketio import SocketIO, join_room, leave_room
|
from flask_socketio import SocketIO, join_room, leave_room
|
||||||
from flask_session import Session
|
from flask_session import Session
|
||||||
from markupsafe import escape
|
from markupsafe import escape
|
||||||
|
@ -10,13 +10,6 @@ preis = 1.5 #Ein Getraenk
|
||||||
#flask_config
|
#flask_config
|
||||||
DATABASE = './Website/mate.db'
|
DATABASE = './Website/mate.db'
|
||||||
|
|
||||||
#def create_logs(app):
|
|
||||||
# now = datetime.datetime.now().strftime('%d-%m-%Y-%H-%M-%S')
|
|
||||||
# logging.basicConfig(filename=f"logs/matekasse-{now}.log",filemode='w', format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ,encoding='utf-8', level=logging.INFO)
|
|
||||||
# app.logger = logging.getLogger('db')
|
|
||||||
#
|
|
||||||
# app.logger.info("Website is starting")
|
|
||||||
|
|
||||||
def log(type=None, userid=None, before=None, after=None):
|
def log(type=None, userid=None, before=None, after=None):
|
||||||
db = get_db()
|
db = get_db()
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
|
@ -64,16 +57,7 @@ def create_app(test_config=None):
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return """
|
return render_template("index.html")
|
||||||
<a href="/list">user and tag list</a>
|
|
||||||
<p>The creator of this website accepts no liability for any linguistic or technical errors!</p>
|
|
||||||
<br style="line-height: 500%;"></br>
|
|
||||||
<a href="/documentation">Doumentation</a><script src="/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous">
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
window.location="/list"
|
|
||||||
</script>
|
|
||||||
"""
|
|
||||||
|
|
||||||
@app.route("/list")
|
@app.route("/list")
|
||||||
def list():
|
def list():
|
||||||
|
@ -81,24 +65,7 @@ def create_app(test_config=None):
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
c.execute("SELECT * FROM users")
|
c.execute("SELECT * FROM users")
|
||||||
users = c.fetchall()
|
users = c.fetchall()
|
||||||
text = ""
|
return render_template("list.html", users=users, preis=preis)
|
||||||
for i in users:
|
|
||||||
text = text + f'<form action="/change" method="post" style="display: inline;"><p style="display: inline;"><a href="list/user?id={i[0]}">{escape(i[1])}</a>: {i[2]/100}€</p><input name="id" type="hidden" value="{i[0]}"> <input name="change" type="number" step="0.01" placeholder="add to balance"></form><form action="/change" method="post" style="display: inline"><input name="id" type="hidden" value="{i[0]}"><button type="submit" name="change" value=-{preis}>-{preis}€</button></form><br style="line-height: 50%;"></br>'
|
|
||||||
return '''<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
var socket = io();
|
|
||||||
socket.on("update", function(){
|
|
||||||
window.location="http://matekasse.server.c3h/list"
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
<title>Strichliste</title>
|
|
||||||
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
|
||||||
<form action="/list/user" method="get"><input name="user" type="search" placeholder="Search for user"><button>Search</button></form>
|
|
||||||
<form action="/adduser" method="post"><button type="submit">Add User</button></form>
|
|
||||||
<br></br>
|
|
||||||
''' + text + '</html>'
|
|
||||||
|
|
||||||
@app.route("/transactionlist")
|
@app.route("/transactionlist")
|
||||||
def transactionlist():
|
def transactionlist():
|
||||||
|
@ -117,41 +84,18 @@ def create_app(test_config=None):
|
||||||
c = db.cursor()
|
c = db.cursor()
|
||||||
id = request.args.get("id")
|
id = request.args.get("id")
|
||||||
c.execute(f"SELECT * FROM users WHERE id=?", [id])
|
c.execute(f"SELECT * FROM users WHERE id=?", [id])
|
||||||
user_list = c.fetchall()
|
user = c.fetchone()
|
||||||
if user_list != []:
|
if user != None :
|
||||||
user = user_list[0]
|
|
||||||
c.execute(f"SELECT * FROM tags WHERE userid={user[0]}")
|
c.execute(f"SELECT * FROM tags WHERE userid={user[0]}")
|
||||||
tags = c.fetchall()
|
tags = c.fetchall()
|
||||||
text = ""
|
return render_template("user.html", user=user, tags=tags)
|
||||||
for tag in tags:
|
|
||||||
text = text + f'<p><form action="/removetag" method="post"><label for="removetag">{tag[0]} </label><input name="id" type="hidden" value="{user[0]}"><input name="tagid" type="hidden" value="{tag[0]}"><button id="removetag" type="submit">Remove Tag</button></form> </p>'
|
|
||||||
return f"""<!DOCTYPE html>
|
|
||||||
<html lang="en">
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
var socket = io();
|
|
||||||
""" + 'socket.on("update", function(){ window.location="http://matekasse.server.c3h/list/user?id=' + id + '"});' + f"""
|
|
||||||
</script>
|
|
||||||
<title>{escape(user[1])}</title>
|
|
||||||
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
|
||||||
<p> {escape(user[1])} : {escape(user[2]/100)}€ <p>
|
|
||||||
<form action="/addtag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Add Tag</button></form>
|
|
||||||
<form action="/removetag" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove Tag</button></form>
|
|
||||||
</p><form action="/change" method="post"><input name="id" type="hidden" value="{user[0]}"> <input name="change" type="number" step="0.01" placeholder="change balance"></form>
|
|
||||||
</p>
|
|
||||||
<br></br>
|
|
||||||
<p>Tags:</p>
|
|
||||||
{text}
|
|
||||||
<br></br>
|
|
||||||
<form action="/removeuser" method="post"><input name="id" type="hidden" value="{user[0]}"><button type="submit">Remove User</button></form>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
else:
|
else:
|
||||||
return render_template("error.html", error_code="043")
|
return render_template("error.html", error_code="043")
|
||||||
|
|
||||||
@app.route("/adduser", methods=['POST'])
|
@app.route("/adduser", methods=['POST'])
|
||||||
def new_user():
|
def new_user():
|
||||||
return render_template("adduser.html")
|
return render_template("adduser.html")
|
||||||
|
|
||||||
@app.route("/removeuser", methods=['POST'])
|
@app.route("/removeuser", methods=['POST'])
|
||||||
def remove_user():
|
def remove_user():
|
||||||
|
@ -166,9 +110,8 @@ def create_app(test_config=None):
|
||||||
app.logger.info(f"Deleted all tags from user ?", [user_id])
|
app.logger.info(f"Deleted all tags from user ?", [user_id])
|
||||||
c.execute(f"DELETE FROM users WHERE id=?", [user_id])
|
c.execute(f"DELETE FROM users WHERE id=?", [user_id])
|
||||||
db.commit()
|
db.commit()
|
||||||
log(type="removeuser", userid=user_id, before=user_name)
|
|
||||||
socketio.emit("update", "update")
|
socketio.emit("update", "update")
|
||||||
return f'<title>remove user</title><p><p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p> <p>Deleted user {escape(user_name)}</p><a href="/list">return to the tags and user list</a></p>'
|
return render_template("removeuser.html", user_name=user_name)
|
||||||
else:
|
else:
|
||||||
return render_template("error.html", error_code="043")
|
return render_template("error.html", error_code="043")
|
||||||
|
|
||||||
|
@ -186,15 +129,8 @@ def create_app(test_config=None):
|
||||||
socketio.emit("update", "update")
|
socketio.emit("update", "update")
|
||||||
c.execute(f"SELECT * FROM users WHERE username=?", [username])
|
c.execute(f"SELECT * FROM users WHERE username=?", [username])
|
||||||
user = c.fetchone()
|
user = c.fetchone()
|
||||||
log(type="adduser", userid=user[0], after=user[1])
|
return render_template("redirect.html")
|
||||||
return """<html>
|
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
window.location="/list";
|
|
||||||
</script>
|
|
||||||
<p>tag was sucsesfully added</p>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
else:
|
else:
|
||||||
return render_template("error.html", error_code="757")
|
return render_template("error.html", error_code="757")
|
||||||
|
|
||||||
|
@ -218,13 +154,7 @@ def create_app(test_config=None):
|
||||||
user = c.fetchone()
|
user = c.fetchone()
|
||||||
log(type="balance", userid=user[0], before=balance_old, after=user[2])
|
log(type="balance", userid=user[0], before=balance_old, after=user[2])
|
||||||
socketio.emit("update", "update")
|
socketio.emit("update", "update")
|
||||||
return """<html>
|
return render_template("redirect.html")
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
|
||||||
<script type="text/javascript" charset="utf-8">
|
|
||||||
window.location="/list";
|
|
||||||
</script>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
else:
|
else:
|
||||||
return render_template("error.html", error_code="043")
|
return render_template("error.html", error_code="043")
|
||||||
|
|
||||||
|
@ -288,13 +218,7 @@ def create_app(test_config=None):
|
||||||
db.commit()
|
db.commit()
|
||||||
message = f"Removed {tag_id} from user {user_id}"
|
message = f"Removed {tag_id} from user {user_id}"
|
||||||
log(type="removetag", userid=user_id, before=tag_id)
|
log(type="removetag", userid=user_id, before=tag_id)
|
||||||
return f"""
|
return render_template("redirect.html")
|
||||||
<html>
|
|
||||||
<script>
|
|
||||||
window.location="/"
|
|
||||||
</script>
|
|
||||||
</html>
|
|
||||||
"""
|
|
||||||
else:
|
else:
|
||||||
return render_template("error.html", error_code="054")
|
return render_template("error.html", error_code="054")
|
||||||
|
|
||||||
|
|
17
Website/templates/confirmation.html
Normal file
17
Website/templates/confirmation.html
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<html>
|
||||||
|
<script src="/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
if (confirm("{message}") == true) {
|
||||||
|
fetch("{{destination}}", {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify({data}),
|
||||||
|
headers: {
|
||||||
|
"Content-type": "application/json; charset=UTF-8"
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location="/list"
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</html>
|
11
Website/templates/index.html
Normal file
11
Website/templates/index.html
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<html>
|
||||||
|
<a href="/list">user and tag list</a>
|
||||||
|
<p>The creator of this website accepts no liability for any linguistic or technical errors!</p>
|
||||||
|
<br style="line-height: 500%;"></br>
|
||||||
|
<a href="/documentation">Doumentation</a>
|
||||||
|
<script src="/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous">
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.location="/list"
|
||||||
|
</script>
|
||||||
|
</html>
|
29
Website/templates/list.html
Normal file
29
Website/templates/list.html
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
var socket = io();
|
||||||
|
socket.on("update", function(){
|
||||||
|
window.location="http://matekasse.server.c3h/list"
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<title>Strichliste</title>
|
||||||
|
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
||||||
|
<form action="/list/user" method="get"><input name="user" type="search" placeholder="Search for user"><button>Search</button></form>
|
||||||
|
<form action="/adduser" method="post"><button type="submit">Add User</button></form>
|
||||||
|
<br></br>
|
||||||
|
{% for i in users %}
|
||||||
|
<form action="/change" method="post" style="display: inline;">
|
||||||
|
<p style="display: inline;">
|
||||||
|
<a href="list/user?id={{i[0]}}">{{i[1]|safe}}</a>: {{i[2]/100}}€
|
||||||
|
</p>
|
||||||
|
<input name="id" type="hidden" value="{{i[0]}}">
|
||||||
|
<input name="change" type="number" step="0.01" placeholder="add to balance">
|
||||||
|
</form>
|
||||||
|
<form action="/change" method="post" style="display: inline">
|
||||||
|
<input name="id" type="hidden" value="{{i[0]}}">
|
||||||
|
<button type="submit" name="change" value=-{{preis}}>-{{preis}}€</button>
|
||||||
|
</form>
|
||||||
|
<br style="line-height: 50%;"></br>
|
||||||
|
{% endfor %}
|
||||||
|
</html>
|
8
Website/templates/redirect.html
Normal file
8
Website/templates/redirect.html
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<html>
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
window.location="/list";
|
||||||
|
</script>
|
||||||
|
<p>redirekting</p>
|
||||||
|
<a href="/list">destination</a>
|
||||||
|
</html>
|
9
Website/templates/removeuser.html
Normal file
9
Website/templates/removeuser.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<html>
|
||||||
|
<title>remove user</title>
|
||||||
|
<p>
|
||||||
|
<p>
|
||||||
|
<a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a>
|
||||||
|
</p>
|
||||||
|
<p>Deleted user {{user_name|safe}}</p>
|
||||||
|
<a href="/list">return to the tags and user list</a>
|
||||||
|
</p>
|
39
Website/templates/user.html
Normal file
39
Website/templates/user.html
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js" integrity="sha512-q/dWJ3kcmjBLU4Qc47E4A9kTB4m3wuTY7vkFJDTZKjTs8jhyGQnaUrxa0Ytd0ssMZhbNua9hE+E7Qv1j+DyZwA==" crossorigin="anonymous"></script>
|
||||||
|
<script type="text/javascript" charset="utf-8">
|
||||||
|
var socket = io();
|
||||||
|
socket.on("update", function(){ window.location="/list/user?id={{user[0]}}"});
|
||||||
|
</script>
|
||||||
|
<title>{{user[1]|safe}}</title>
|
||||||
|
<p><a href="/list">user and tag list</a> | <a href="/documentation">Documentation</a></p>
|
||||||
|
<p> {{user[1]|safe}} : {{user[2]/100}}€ <p>
|
||||||
|
<form action="/addtag" method="post">
|
||||||
|
<input name="id" type="hidden" value="{{user[0]}}">
|
||||||
|
<button type="submit">Add Tag</button>
|
||||||
|
</form>
|
||||||
|
<form action="/removetag" method="post">
|
||||||
|
<input name="id" type="hidden" value="{{user[0]}}">
|
||||||
|
<button type="submit">Remove Tag</button>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
<form action="/change" method="post">
|
||||||
|
<input name="id" type="hidden" value="{{user[0]}}">
|
||||||
|
<input name="change" type="number" step="0.01" placeholder="change balance">
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
<br></br>
|
||||||
|
<p>Tags:</p>
|
||||||
|
{% for tag in tags %}
|
||||||
|
<p>
|
||||||
|
<form action="/removetag" method="post">
|
||||||
|
<label for="removetag">{{tag[0]}} </label>
|
||||||
|
<input name="id" type="hidden" value="{{user[0]}}">
|
||||||
|
<input name="tagid" type="hidden" value="{{tag[0]}}">
|
||||||
|
<button id="removetag" type="submit">Remove Tag</button>
|
||||||
|
</form>
|
||||||
|
</p>
|
||||||
|
{% endfor %}
|
||||||
|
<br></br>
|
||||||
|
<form action="/removeuser" method="post"><input name="id" type="hidden" value="{{user[0]}}"><button type="submit">Remove User</button></form>
|
||||||
|
</html>
|
Loading…
Reference in a new issue