added filter fpr length in list and transactionlist

This commit is contained in:
bton 2024-06-05 21:57:30 +02:00
parent a6dd6310b7
commit b8f54c497e
3 changed files with 18 additions and 3 deletions

View file

@ -10,6 +10,13 @@ preis = -150 #Ein Getraenk
#flask_config #flask_config
DATABASE = './Website/mate.db' 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): def create_app(test_config=None):
app = Flask(__name__) app = Flask(__name__)
key = str(uuid.uuid4().hex) key = str(uuid.uuid4().hex)
@ -17,6 +24,7 @@ def create_app(test_config=None):
app.config['SESSION_TYPE'] = 'filesystem' app.config['SESSION_TYPE'] = 'filesystem'
app.config['SECRET_KEY'] = key app.config['SECRET_KEY'] = key
app.config['DATABASE'] = DATABASE app.config['DATABASE'] = DATABASE
app.jinja_env.filters['limit_length'] = limit_length
else: else:
app.config.from_mapping(test_config) app.config.from_mapping(test_config)
@ -34,7 +42,7 @@ def create_app(test_config=None):
# db = getattr(g, '_database', None) # db = getattr(g, '_database', None)
# if db is not None: # if db is not None:
# db.close() # db.close()
# app.logger.info("Website exited") # appt.logger.info("Website exited")
#var #var
user_queue = queue.Queue() user_queue = queue.Queue()

View file

@ -21,7 +21,7 @@ Strichliste
{% for user in users %} {% for user in users %}
<form action="/change" method="post" style="display: inline;"> <form action="/change" method="post" style="display: inline;">
<p style="display: inline;"> <p style="display: inline;">
<a href="list/user?id={{user[0]}}">{{user[1]}}</a>: {{user[2]/100}}€ <a href="list/user?id={{user[0]}}">{{user[1]|limit_length}}</a>: {{user[2]/100}}€
</p> </p>
<input name="id" type="hidden" value="{{user[0]}}"> <input name="id" type="hidden" value="{{user[0]}}">
<input name="change" type="number" lang="nb" step="0.01" max={{50000-user[2]/100}} min={{min_value-user[2]/100}} placeholder="add to balance"> <input name="change" type="number" lang="nb" step="0.01" max={{50000-user[2]/100}} min={{min_value-user[2]/100}} placeholder="add to balance">

View file

@ -4,7 +4,14 @@ Transactionlist
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% for action in action_list%} {% for action in action_list%}
<form action="/api/change" method="post"><p style="display: inline;">{{action["statement"]}} userid:{{action["user_id"]}} {{action["before"]}} {{action["after"]}} {{action["change"]}}</p><input type="hidden" name="statement" value={{action["reverse_statement"]}}><input type="hidden" name="user_id" value={{action["reverse_user_id"]}}><input type="hidden" name="before" value={{action["reverse_before"]}}><input type="hidden" name="after" value={{action["reverse_after"]}}><input type="hidden" name="change" value={{action["reverse_change"]}}><button type="submit">rollback</button></form><br></br> <form action="/api/change" method="post">
<p style="display: inline;">{{action["statement"]}} userid:{{action["user_id"]}} {{action["before"|limit_length]}} {{action["after"]|limit_length}} {{action["change"]}}</p>
<input type="hidden" name="statement" value={{action["reverse_statement"]}}>
<input type="hidden" name="user_id" value={{action["reverse_user_id"]}}>
<input type="hidden" name="before" value={{action["reverse_before"]}}>
<input type="hidden" name="after" value={{action["reverse_after"]}}>
<input type="hidden" name="change" value={{action["reverse_change"]}}>
<button type="submit">rollback</button></form><br></br>
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}