Preis-Eingabe auf europäisches Komma-Format normalisiert

- Neuer Artikel: Textfeld mit Placeholder 4,50 statt Dezimalpunkt
- Artikel bearbeiten: Preise mit Komma anzeigen und akzeptieren
- Backend: Komma vor float()-Konvertierung in Punkt umwandeln

Made-with: Cursor
This commit is contained in:
2026-03-22 17:04:30 +01:00
parent 5c8c4a947e
commit bd4664f23b
2 changed files with 14 additions and 6 deletions

12
app.py
View File

@@ -221,7 +221,11 @@ def admin(instance_id):
if action == "add_product":
name = request.form.get('add_name', '').strip()
price = request.form.get('add_price', type=float)
price_str = request.form.get('add_price', '').replace(',', '.').strip()
try:
price = float(price_str) if price_str else None
except ValueError:
price = None
icon = request.form.get('add_icon', '🛒').strip() or '🛒'
color = request.form.get('add_color', 'btn-primary')
if name and price is not None:
@@ -244,7 +248,11 @@ def admin(instance_id):
for row in products_rows:
pos = row['position']
name = request.form.get(f'name_{pos}')
price = request.form.get(f'price_{pos}', type=float)
price_str = request.form.get(f'price_{pos}', '').replace(',', '.').strip()
try:
price = float(price_str) if price_str else None
except ValueError:
price = None
icon = request.form.get(f'icon_{pos}')
color = request.form.get(f'color_{pos}')
if name is not None and price is not None:

View File

@@ -45,8 +45,8 @@
<td class="align-middle">{{ pos }}</td>
<td><input type="text" class="form-control" name="name_{{ pos }}" value="{{ prod['name'] }}"
required></td>
<td><input type="number" step="0.01" class="form-control" name="price_{{ pos }}"
value="{{ prod['price'] }}" required></td>
<td><input type="text" inputmode="decimal" class="form-control" name="price_{{ pos }}"
value="{{ '{:.2f}'.format(prod['price']).replace('.', ',') }}" required></td>
<td><input type="text" class="form-control" name="icon_{{ pos }}" value="{{ prod['icon'] }}"
required></td>
<td>
@@ -100,8 +100,8 @@
</div>
<div class="form-group col-md-2">
<label for="add_price">Preis (€)</label>
<input type="number" step="0.01" class="form-control" name="add_price" id="add_price" required
placeholder="4.50">
<input type="text" inputmode="decimal" class="form-control" name="add_price" id="add_price" required
placeholder="4,50">
</div>
<div class="form-group col-md-1">
<label for="add_icon">Icon</label>