improved mechanism for detecting quantities

This commit is contained in:
2026-01-03 15:05:13 +01:00
parent 3ae2869106
commit 15de0758b4
3 changed files with 47 additions and 12 deletions
+41 -6
View File
@@ -46,19 +46,52 @@ def items_append(listid):
unit = '' unit = ''
quantity = '' quantity = ''
if ' ' in newlabel: if ' ' in newlabel:
# could be:
# paard 5
# paard 5 poten
# 3 paarden
# 3kilo schaap
# 3 kilo schaap
# take the last word # take the last word
words = newlabel.split(' ') words = newlabel.split(' ')
# -1- if there is a digit in the last word
if any(char.isdigit() for char in words[-1]): if any(char.isdigit() for char in words[-1]):
# there is a numeric value # ... paard 5
# ... paard 5poten
for char in words[-1]: for char in words[-1]:
if char.isdigit(): if char.isdigit():
quantity += char quantity += char
else: else:
unit += char unit += char
newlabel = ' '.join(words[0:-1])
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
else:
unit += char
unit = words[-1] if unit=='' else unit+' '+words[-1]
newlabel = ' '.join(words[0:-2])
elif any(char.isdigit() for char in words[0]):
# 5 paarden
# 5koppig paarden
for char in words[0]:
if char.isdigit():
quantity += char
else:
unit += char
newlabel = ' '.join(words[1:])
if unit=='':
if len(words)>2 and len(words[1])<=4:
unit = words[1]
newlabel = ' '.join(words[2:])
if unit == '': if unit == '':
unit = 'x' unit = 'x'
newlabel = ' '.join(words[0:-1])
newlabel=newlabel.title()
newitem=Item(listofitems_id=listid, label=newlabel) newitem=Item(listofitems_id=listid, label=newlabel)
if unit: if unit:
newitem.unit = unit newitem.unit = unit
@@ -75,6 +108,7 @@ def items_append(listid):
icon_names.append(os.path.splitext(i)[0]) icon_names.append(os.path.splitext(i)[0])
return render_template("items_append.html", user=current_user, return render_template("items_append.html", user=current_user,
listid=listid,
items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(), items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(),
icons = icon_names, icons = icon_names,
iconpath = '/'+ICONPATH, iconpath = '/'+ICONPATH,
@@ -89,10 +123,11 @@ def item_delete(itemid):
db.session.delete(i) db.session.delete(i)
db.session.commit() db.session.commit()
Log.info(f'User {current_user.id} deleted item {itemid}') Log.info(f'User {current_user.id} deleted item {itemid}')
return render_template("items_append.html", user=current_user, # return render_template("items_append.html", user=current_user,
items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(), # items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(),
iconpath = '/'+ICONPATH, # iconpath = '/'+ICONPATH,
logo_url=url_for("items.items", listid=listid)) # logo_url=url_for("items.items", listid=listid))
return redirect(url_for("items.items_append", listid=listid))
# webservice for cleaning all checked items to suggestion # webservice for cleaning all checked items to suggestion
@items_bp.route("/items_clean/<listid>") @items_bp.route("/items_clean/<listid>")
+2 -2
View File
@@ -2,7 +2,7 @@
"name": "List App", "name": "List App",
"short_name": "L@pp", "short_name": "L@pp",
"start_url": "/", "start_url": "/",
"display": "standalone", // Or "minimal-ui" for a more browser-like feel on iOS "display": "standalone",
"background_color": "transparent", "background_color": "transparent",
"theme_color": "transparent", "theme_color": "transparent",
"icons": [ "icons": [
@@ -20,7 +20,7 @@
"src": "/static/lapp1024.png", "src": "/static/lapp1024.png",
"sizes": "1024x1024", "sizes": "1024x1024",
"type": "image/png", "type": "image/png",
"purpose": "maskable" // Good for modern iOS devices "purpose": "maskable"
} }
] ]
} }
+1 -1
View File
@@ -42,7 +42,7 @@ $(document).ready(function(){
</script> </script>
<form method="post"> <form method="post" action="/items_append/{{ listid }}">
<div class=".container"> <div class=".container">
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<input class="form-control" id="myInput" type="text" name="newItem" placeholder="Search.."/> <input class="form-control" id="myInput" type="text" name="newItem" placeholder="Search.."/>