added multiline append
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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_<n>" where <N> 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)
|
||||
|
||||
|
||||
@@ -77,6 +77,17 @@ $(document).ready(function(){
|
||||
</tbody>
|
||||
</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>
|
||||
|
||||
<button class="btn btn-secondary">+</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<!-- Modal -->
|
||||
<div class="modal fade" id="staticBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
|
||||
Reference in New Issue
Block a user