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
|
||||
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_session import Session
|
||||
from markupsafe import escape
|
||||
|
@ -10,13 +10,6 @@ preis = 1.5 #Ein Getraenk
|
|||
#flask_config
|
||||
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):
|
||||
db = get_db()
|
||||
c = db.cursor()
|
||||
|
@ -64,16 +57,7 @@ def create_app(test_config=None):
|
|||
|
||||
@app.route("/")
|
||||
def index():
|
||||
return """
|
||||
<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>
|
||||
"""
|
||||
return render_template("index.html")
|
||||
|
||||
@app.route("/list")
|
||||
def list():
|
||||
|
@ -81,24 +65,7 @@ def create_app(test_config=None):
|
|||
c = db.cursor()
|
||||
c.execute("SELECT * FROM users")
|
||||
users = c.fetchall()
|
||||
text = ""
|
||||
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>'
|
||||
return render_template("list.html", users=users, preis=preis)
|
||||
|
||||
@app.route("/transactionlist")
|
||||
def transactionlist():
|
||||
|
@ -117,41 +84,18 @@ def create_app(test_config=None):
|
|||
c = db.cursor()
|
||||
id = request.args.get("id")
|
||||
c.execute(f"SELECT * FROM users WHERE id=?", [id])
|
||||
user_list = c.fetchall()
|
||||
if user_list != []:
|
||||
user = user_list[0]
|
||||
user = c.fetchone()
|
||||
if user != None :
|
||||
c.execute(f"SELECT * FROM tags WHERE userid={user[0]}")
|
||||
tags = c.fetchall()
|
||||
text = ""
|
||||
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>
|
||||
"""
|
||||
return render_template("user.html", user=user, tags=tags)
|
||||
|
||||
else:
|
||||
return render_template("error.html", error_code="043")
|
||||
|
||||
|
||||
@app.route("/adduser", methods=['POST'])
|
||||
def new_user():
|
||||
return render_template("adduser.html")
|
||||
return render_template("adduser.html")
|
||||
|
||||
@app.route("/removeuser", methods=['POST'])
|
||||
def remove_user():
|
||||
|
@ -166,9 +110,8 @@ def create_app(test_config=None):
|
|||
app.logger.info(f"Deleted all tags from user ?", [user_id])
|
||||
c.execute(f"DELETE FROM users WHERE id=?", [user_id])
|
||||
db.commit()
|
||||
log(type="removeuser", userid=user_id, before=user_name)
|
||||
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:
|
||||
return render_template("error.html", error_code="043")
|
||||
|
||||
|
@ -186,15 +129,8 @@ def create_app(test_config=None):
|
|||
socketio.emit("update", "update")
|
||||
c.execute(f"SELECT * FROM users WHERE username=?", [username])
|
||||
user = c.fetchone()
|
||||
log(type="adduser", userid=user[0], after=user[1])
|
||||
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>
|
||||
"""
|
||||
return render_template("redirect.html")
|
||||
|
||||
else:
|
||||
return render_template("error.html", error_code="757")
|
||||
|
||||
|
@ -218,13 +154,7 @@ def create_app(test_config=None):
|
|||
user = c.fetchone()
|
||||
log(type="balance", userid=user[0], before=balance_old, after=user[2])
|
||||
socketio.emit("update", "update")
|
||||
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>
|
||||
</html>
|
||||
"""
|
||||
return render_template("redirect.html")
|
||||
else:
|
||||
return render_template("error.html", error_code="043")
|
||||
|
||||
|
@ -288,13 +218,7 @@ def create_app(test_config=None):
|
|||
db.commit()
|
||||
message = f"Removed {tag_id} from user {user_id}"
|
||||
log(type="removetag", userid=user_id, before=tag_id)
|
||||
return f"""
|
||||
<html>
|
||||
<script>
|
||||
window.location="/"
|
||||
</script>
|
||||
</html>
|
||||
"""
|
||||
return render_template("redirect.html")
|
||||
else:
|
||||
return render_template("error.html", error_code="054")
|
||||
|
||||
|
|
|
@ -5,4 +5,4 @@
|
|||
<p>
|
||||
<form action="/adduser/user" method="post"><input name="username" type="search" placeholder="Username"><button>Add user</button></form>
|
||||
</p>
|
||||
</html>
|
||||
</html>
|
||||
|
|
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