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 goudr
#. appel zilver 4 #. appel zilver 4
#. appel zilver 4kratten #. appel zilver 4kratten
print(newlabel)
unit = '' unit = ''
quantity = '' quantity = ''
if ' ' in newlabel: 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]): elif len(words)>2 and any(char.isdigit() for char in words[-2]):
# ... paard 5 poten # ... paard 5 poten
# ... paard 4keer poten # ... paard 4keer poten
print(words)
for char in words[-2]: for char in words[-2]:
if char.isdigit(): if char.isdigit():
quantity += char quantity += char
@@ -91,8 +89,6 @@ def interpret_and_add_item(listid, newlabel):
# check if the item exists already # check if the item exists already
item = Item.query.filter_by(listofitems_id=listid, label=newlabel, unit=unit).first() item = Item.query.filter_by(listofitems_id=listid, label=newlabel, unit=unit).first()
if item: if item:
print(item.unit)
print(unit)
if item.is_checked: if item.is_checked:
item.quantity += int(quantity) item.quantity += int(quantity)
if item.is_suggestion: if item.is_suggestion:
@@ -135,6 +131,20 @@ def items_append(listid):
iconpath = '/'+ICONPATH, iconpath = '/'+ICONPATH,
logo_url=url_for("items.items", listid=listid)) 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 # webservice for deleting one item
@items_bp.route("/item_delete/<itemid>") @items_bp.route("/item_delete/<itemid>")
@login_required @login_required
@@ -187,7 +197,6 @@ def item_addone(itemid):
@login_required @login_required
def item_addquantity(itemid, quantity): def item_addquantity(itemid, quantity):
i = Item.query.get(itemid) i = Item.query.get(itemid)
print(f"{i.quantity} / {quantity}")
listid = i.listofitems_id listid = i.listofitems_id
# always add the item to the active todo # always add the item to the active todo
if i.is_suggestion or i.is_checked: if i.is_suggestion or i.is_checked:
-7
View File
@@ -28,15 +28,12 @@ def edit():
if "iid" in request.form: if "iid" in request.form:
ilist_id = int(request.form["iid"]) ilist_id = int(request.form["iid"])
newname = request.form["name"] newname = request.form["name"]
print(ilist_id)
print(newname)
double = False double = False
for d in ListOfItems.query.filter_by(owner_user_id=current_user.id, name=newname).all(): for d in ListOfItems.query.filter_by(owner_user_id=current_user.id, name=newname).all():
if not d.id == ilist_id: if not d.id == ilist_id:
# there is a duplicate name # there is a duplicate name
double = True double = True
if double: 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) 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 # 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(item)
db.session.delete(ilist) db.session.delete(ilist)
else: else:
print("not to be deleted but updated")
# update name # update name
ilist.name = newname ilist.name = newname
# update active # update active
@@ -58,13 +54,10 @@ def edit():
# sharing. there may be 0 or more chacboces named "sharing_<n>" where <N> is the user.id # sharing. there may be 0 or more chacboces named "sharing_<n>" where <N> is the user.id
# first, remoe all the existing shares # first, remoe all the existing shares
for s in Shared.query.filter_by(listofitem_id=ilist_id).all(): 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) db.session.delete(s)
# and then rebuild them # and then rebuild them
for u in not_current_user(current_user.id): for u in not_current_user(current_user.id):
print(f"tryin user {u.id}")
if f"shares_{u.id}" in request.form: if f"shares_{u.id}" in request.form:
print(f"found sharebox: {u.id}")
shared1 = Shared(user_id=u.id, listofitem_id=ilist_id) shared1 = Shared(user_id=u.id, listofitem_id=ilist_id)
db.session.add(shared1) db.session.add(shared1)
+11
View File
@@ -77,6 +77,17 @@ $(document).ready(function(){
</tbody> </tbody>
</table> </table>
<br/>
<form method="post" action="/items_multiappend/{{ listid }}">
<div class=".container">
<div class="d-flex justify-content-between">
<textarea class="form-control" id="myInput" rows="4" name="newItems" placeholder="many items..."></textarea>
&nbsp;
<button class="btn btn-secondary">+</button>
</div>
</div>
</form>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true"> <div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">