added multiline append

This commit is contained in:
2026-01-03 16:10:59 +01:00
parent 9013d48883
commit cc4863a063
3 changed files with 25 additions and 12 deletions
+14 -5
View File
@@ -36,7 +36,6 @@ def interpret_and_add_item(listid, newlabel):
# appel goudr
#. appel zilver 4
#. appel zilver 4kratten
print(newlabel)
unit = ''
quantity = ''
if ' ' in newlabel:
@@ -61,7 +60,6 @@ def interpret_and_add_item(listid, newlabel):
elif len(words)>2 and any(char.isdigit() for char in words[-2]):
# ... paard 5 poten
# ... paard 4keer poten
print(words)
for char in words[-2]:
if char.isdigit():
quantity += char
@@ -91,8 +89,6 @@ def interpret_and_add_item(listid, newlabel):
# check if the item exists already
item = Item.query.filter_by(listofitems_id=listid, label=newlabel, unit=unit).first()
if item:
print(item.unit)
print(unit)
if item.is_checked:
item.quantity += int(quantity)
if item.is_suggestion:
@@ -135,6 +131,20 @@ def items_append(listid):
iconpath = '/'+ICONPATH,
logo_url=url_for("items.items", listid=listid))
# user adds items to list
@items_bp.route("/items_multiappend/<listid>", methods=["GET", "POST"])
@login_required
def items_multiappend(listid):
if request.method == "POST":
# a new item has been added
newitems = request.form["newItems"]
for line in newitems.splitlines():
line = line.strip()
if len(line)>2:
interpret_and_add_item(listid, line.strip())
return redirect(url_for("items.items_append", listid=listid))
# webservice for deleting one item
@items_bp.route("/item_delete/<itemid>")
@login_required
@@ -187,7 +197,6 @@ def item_addone(itemid):
@login_required
def item_addquantity(itemid, quantity):
i = Item.query.get(itemid)
print(f"{i.quantity} / {quantity}")
listid = i.listofitems_id
# always add the item to the active todo
if i.is_suggestion or i.is_checked: