From 5179ec792cb14e80edf5728d694988d8cfa32366 Mon Sep 17 00:00:00 2001 From: bton Date: Sat, 17 Feb 2024 02:12:27 +0100 Subject: [PATCH] jinja --- Website/__init__.py | 104 ++++------------------------ Website/templates/adduser.html | 2 +- Website/templates/confirmation.html | 17 +++++ Website/templates/index.html | 11 +++ Website/templates/list.html | 29 ++++++++ Website/templates/redirect.html | 8 +++ Website/templates/removeuser.html | 9 +++ Website/templates/user.html | 39 +++++++++++ 8 files changed, 128 insertions(+), 91 deletions(-) create mode 100644 Website/templates/confirmation.html create mode 100644 Website/templates/index.html create mode 100644 Website/templates/list.html create mode 100644 Website/templates/redirect.html create mode 100644 Website/templates/removeuser.html create mode 100644 Website/templates/user.html diff --git a/Website/__init__.py b/Website/__init__.py index 71b264c..dc82896 100644 --- a/Website/__init__.py +++ b/Website/__init__.py @@ -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 """ - user and tag list -

The creator of this website accepts no liability for any linguistic or technical errors!

-

- Doumentation - - """ + 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'

{escape(i[1])}: {i[2]/100}€



' - return ''' - - - - Strichliste -

user and tag list | Documentation

-
-
-

- ''' + text + '' + 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'

' - return f""" - - - - {escape(user[1])} -

user and tag list | Documentation

-

{escape(user[1])} : {escape(user[2]/100)}€

-

-
-

-

-

-

Tags:

- {text} -

-
- - """ + 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'remove user

user and tag list | Documentation

Deleted user {escape(user_name)}

return to the tags and user list

' + 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 """ - - -

tag was sucsesfully added

- - """ + 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 """ - - - - """ + 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""" - - - - """ + return render_template("redirect.html") else: return render_template("error.html", error_code="054") diff --git a/Website/templates/adduser.html b/Website/templates/adduser.html index 7368ebe..a1a74e0 100644 --- a/Website/templates/adduser.html +++ b/Website/templates/adduser.html @@ -5,4 +5,4 @@

- \ No newline at end of file + diff --git a/Website/templates/confirmation.html b/Website/templates/confirmation.html new file mode 100644 index 0000000..b6b96e4 --- /dev/null +++ b/Website/templates/confirmation.html @@ -0,0 +1,17 @@ + + + + diff --git a/Website/templates/index.html b/Website/templates/index.html new file mode 100644 index 0000000..75f4c32 --- /dev/null +++ b/Website/templates/index.html @@ -0,0 +1,11 @@ + + user and tag list +

The creator of this website accepts no liability for any linguistic or technical errors!

+

+ Doumentation + + + diff --git a/Website/templates/list.html b/Website/templates/list.html new file mode 100644 index 0000000..37e1a42 --- /dev/null +++ b/Website/templates/list.html @@ -0,0 +1,29 @@ + + + + + Strichliste +

user and tag list | Documentation

+
+
+

+ {% for i in users %} +
+

+ {{i[1]|safe}}: {{i[2]/100}}€ +

+ + +
+
+ + +
+

+ {% endfor %} + diff --git a/Website/templates/redirect.html b/Website/templates/redirect.html new file mode 100644 index 0000000..9848c78 --- /dev/null +++ b/Website/templates/redirect.html @@ -0,0 +1,8 @@ + + + +

redirekting

+ destination + diff --git a/Website/templates/removeuser.html b/Website/templates/removeuser.html new file mode 100644 index 0000000..b6c9ea6 --- /dev/null +++ b/Website/templates/removeuser.html @@ -0,0 +1,9 @@ + + remove user +

+

+ user and tag list | Documentation +

+

Deleted user {{user_name|safe}}

+ return to the tags and user list +

diff --git a/Website/templates/user.html b/Website/templates/user.html new file mode 100644 index 0000000..db30f4b --- /dev/null +++ b/Website/templates/user.html @@ -0,0 +1,39 @@ + + + + + {{user[1]|safe}} +

user and tag list | Documentation

+

{{user[1]|safe}} : {{user[2]/100}}€

+

+ + +
+
+ + +
+

+
+ + +
+

+

+

Tags:

+ {% for tag in tags %} +

+

+ + + + +
+

+ {% endfor %} +

+
+