From b8f54c497e2ef2ebc7bad46be382412a580a6149 Mon Sep 17 00:00:00 2001 From: bton Date: Wed, 5 Jun 2024 21:57:30 +0200 Subject: [PATCH] added filter fpr length in list and transactionlist --- Website/__init__.py | 10 +++++++++- Website/templates/list.html | 2 +- Website/templates/transactionlist.html | 9 ++++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Website/__init__.py b/Website/__init__.py index bba03dc..307dace 100644 --- a/Website/__init__.py +++ b/Website/__init__.py @@ -10,6 +10,13 @@ preis = -150 #Ein Getraenk #flask_config DATABASE = './Website/mate.db' +def limit_length(text, length=50): + if type(text) != str: + text = str(text) + if len(text) > length: + return f"{text[:(length -3)]}..." + return text + def create_app(test_config=None): app = Flask(__name__) key = str(uuid.uuid4().hex) @@ -17,6 +24,7 @@ def create_app(test_config=None): app.config['SESSION_TYPE'] = 'filesystem' app.config['SECRET_KEY'] = key app.config['DATABASE'] = DATABASE + app.jinja_env.filters['limit_length'] = limit_length else: app.config.from_mapping(test_config) @@ -34,7 +42,7 @@ def create_app(test_config=None): # db = getattr(g, '_database', None) # if db is not None: # db.close() - # app.logger.info("Website exited") + # appt.logger.info("Website exited") #var user_queue = queue.Queue() diff --git a/Website/templates/list.html b/Website/templates/list.html index 07bfad3..1769c42 100644 --- a/Website/templates/list.html +++ b/Website/templates/list.html @@ -21,7 +21,7 @@ Strichliste {% for user in users %}

- {{user[1]}}: {{user[2]/100}}€ + {{user[1]|limit_length}}: {{user[2]/100}}€

diff --git a/Website/templates/transactionlist.html b/Website/templates/transactionlist.html index 4359b3a..2259358 100644 --- a/Website/templates/transactionlist.html +++ b/Website/templates/transactionlist.html @@ -4,7 +4,14 @@ Transactionlist {% endblock %} {% block content %} {% for action in action_list%} -

{{action["statement"]}} userid:{{action["user_id"]}} {{action["before"]}} {{action["after"]}} {{action["change"]}}



+
+

{{action["statement"]}} userid:{{action["user_id"]}} {{action["before"|limit_length]}} {{action["after"]|limit_length}} {{action["change"]}}

+ + + + + +


{% endfor %} {% endblock %}