From cc4863a0638b388bba371875274d6a5d76b202da Mon Sep 17 00:00:00 2001 From: Ignace Date: Sat, 3 Jan 2026 16:10:59 +0100 Subject: [PATCH] added multiline append --- items.py | 19 ++++++++++++++----- lists.py | 7 ------- templates/items_append.html | 11 +++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/items.py b/items.py index 07310b4..37d3593 100644 --- a/items.py +++ b/items.py @@ -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/", 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/") @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: diff --git a/lists.py b/lists.py index f85ef65..57ad7d4 100644 --- a/lists.py +++ b/lists.py @@ -28,15 +28,12 @@ def edit(): if "iid" in request.form: ilist_id = int(request.form["iid"]) newname = request.form["name"] - print(ilist_id) - print(newname) double = False for d in ListOfItems.query.filter_by(owner_user_id=current_user.id, name=newname).all(): if not d.id == ilist_id: # there is a duplicate name double = True if double: - print("found double") return render_template("lists_edit.html", user=current_user, ilists=current_user.my_owned_lists(with_inactive=True), newlist=newlist, error_id=ilist_id) # if id already exists, overwrite the existing list, else create a new one @@ -50,7 +47,6 @@ def edit(): db.session.delete(item) db.session.delete(ilist) else: - print("not to be deleted but updated") # update name ilist.name = newname # update active @@ -58,13 +54,10 @@ def edit(): # sharing. there may be 0 or more chacboces named "sharing_" where is the user.id # first, remoe all the existing shares for s in Shared.query.filter_by(listofitem_id=ilist_id).all(): - print(f"deleting {s.user_id} - {s.listofitem_id}") db.session.delete(s) # and then rebuild them for u in not_current_user(current_user.id): - print(f"tryin user {u.id}") if f"shares_{u.id}" in request.form: - print(f"found sharebox: {u.id}") shared1 = Shared(user_id=u.id, listofitem_id=ilist_id) db.session.add(shared1) diff --git a/templates/items_append.html b/templates/items_append.html index 497b484..0785887 100644 --- a/templates/items_append.html +++ b/templates/items_append.html @@ -77,6 +77,17 @@ $(document).ready(function(){ +
+ +
+
+
+ +   + +
+
+