This commit is contained in:
moerp 2024-01-30 18:07:16 +01:00
parent 39e2f2634d
commit 4761910092
4 changed files with 27 additions and 19 deletions

View File

@ -66,7 +66,6 @@ def get_products():
with conn.cursor() as cursor: with conn.cursor() as cursor:
cursor.execute('SELECT name FROM nutrition_table') cursor.execute('SELECT name FROM nutrition_table')
products = cursor.fetchall() products = cursor.fetchall()
print("ter")
return {'products': [product[0] for product in products]} return {'products': [product[0] for product in products]}
finally: finally:
if conn: if conn:
@ -97,19 +96,24 @@ def add_lm():
return "Lebensmittel nicht gefunden.", 404 return "Lebensmittel nicht gefunden.", 404
def convert_decimal(value):
try:
return float(value.replace(',', '.'))
except (ValueError, TypeError):
return 0.0 # Rückgabe eines Standardwertes im Fehlerfall
@app.route('/add_nutrition', methods=['POST']) @app.route('/add_nutrition', methods=['POST'])
@oidc.accept_token(require_token=True, scopes_required=['openid']) @oidc.accept_token(require_token=True, scopes_required=['openid'])
def add_nutrition(): def add_nutrition():
food = request.form.get('food') food = request.form.get('food')
kcal = float(request.form.get('kcal')) kcal = convert_decimal(request.form.get('kcal'))
ew = float(request.form.get('ew')) ew = convert_decimal(request.form.get('ew'))
fett = float(request.form.get('fett')) fett = convert_decimal(request.form.get('fett'))
kh = float(request.form.get('kh')) kh = convert_decimal(request.form.get('kh'))
bst = float(request.form.get('bst')) bst = convert_decimal(request.form.get('bst'))
ca = float(request.form.get('ca')) ca = convert_decimal(request.form.get('ca'))
print("test")
# Verbindung zur Datenbank herstellen und Daten einfügen # Verbindung zur Datenbank herstellen und Daten einfügen
try: try:
conn = psycopg2.connect() conn = psycopg2.connect()

View File

@ -34,7 +34,7 @@ button:not(:disabled):hover {
} }
button#remove-button { button#remove-button {
background-color: #f443366f; /* Helles Rot */ background-color: #640000; /* Helles Rot */
} }
button#remove-button:disabled { button#remove-button:disabled {
@ -43,7 +43,7 @@ button#remove-button:disabled {
} }
button#remove-button:not(:disabled):hover { button#remove-button:not(:disabled):hover {
background-color: #d32f2f3d; /* Dunkleres Rot */ background-color: #490000; /* Dunkleres Rot */
} }
@ -72,7 +72,7 @@ tr:nth-child(even) {
} }
.selected, tr.selected { .selected, tr.selected {
background-color: #ffdd99; /* Hervorhebung der Auswahl */ background-color: #e19595; /* Hervorhebung der Auswahl */
} }
tr:hover:not(.selected) { tr:hover:not(.selected) {

View File

@ -175,7 +175,7 @@ function updateTotalNutrition() {
</head> </head>
<body> <body>
<nav id="navbar"> <nav id="navbar">
<h1>Elos Rezept Rechner</h1> <h1>Elo's Rezept Rechner</h1>
<ul> <ul>
<li><a href="/" class="active">Rechner</a></li> <li><a href="/" class="active">Rechner</a></li>
<li><a href="/nutrition">Neue Lebensmittel</a></li> <li><a href="/nutrition">Neue Lebensmittel</a></li>
@ -210,6 +210,8 @@ function updateTotalNutrition() {
<button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button> <button id="remove-button" onclick="removeSelectedRow()" disabled>Entfernen</button>
<table id="total-nutrition-table"> <table id="total-nutrition-table">
<tr> <tr>
<th>Lebensmittel</th>
<th>Gewicht (g)</th>
<th>kcal</th> <th>kcal</th>
<th>EW</th> <th>EW</th>
<th>Fett</th> <th>Fett</th>
@ -218,6 +220,8 @@ function updateTotalNutrition() {
<th>CA</th> <th>CA</th>
</tr> </tr>
<tr> <tr>
<t>Gesamtwerte</td>
<td></td>-</td>
<td id="total-kcal">0</td> <td id="total-kcal">0</td>
<td id="total-ew">0</td> <td id="total-ew">0</td>
<td id="total-fett">0</td> <td id="total-fett">0</td>

View File

@ -44,7 +44,7 @@
</head> </head>
<body> <body>
<nav id="navbar"> <nav id="navbar">
<h1>Elos Rezept Rechner</h1> <h1>Elo's Rezept Rechner</h1>
<ul> <ul>
<li><a href="/">Rechner</a></li> <li><a href="/">Rechner</a></li>
<li><a href="/nutrition" class="active">Neue Lebensmittel</a></li> <li><a href="/nutrition" class="active">Neue Lebensmittel</a></li>
@ -65,12 +65,12 @@
</tr> </tr>
<tr> <tr>
<td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td> <td><input type="text" name="food" placeholder="Lebensmittel" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kcal" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="kcal" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ew" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="ew" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="fett" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="fett" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="kh" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="kh" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="bst" pattern="\d+(\.\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="bst" pattern="\d+([.,]\d{1,2})?" placeholder="g" oninput="updateSubmitButtonState()"></td>
<td><input <input type="text" name="ca" pattern="\d+(\.\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td> <td><input <input type="text" name="ca" pattern="\d+([.,]\d{1,2})?" placeholder="mg" oninput="updateSubmitButtonState()"></td>
</tr> </tr>
</table> </table>
<button type="submit" id="submit-button" disabled>Hinzufügen</button> <button type="submit" id="submit-button" disabled>Hinzufügen</button>