improved mechanism for detecting quantities
This commit is contained in:
@@ -46,20 +46,53 @@ def items_append(listid):
|
||||
unit = ''
|
||||
quantity = ''
|
||||
if ' ' in newlabel:
|
||||
# could be:
|
||||
# paard 5
|
||||
# paard 5 poten
|
||||
# 3 paarden
|
||||
# 3kilo schaap
|
||||
# 3 kilo schaap
|
||||
# take the last word
|
||||
words = newlabel.split(' ')
|
||||
# -1- if there is a digit in the last word
|
||||
if any(char.isdigit() for char in words[-1]):
|
||||
# there is a numeric value
|
||||
# ... paard 5
|
||||
# ... paard 5poten
|
||||
for char in words[-1]:
|
||||
if char.isdigit():
|
||||
quantity += char
|
||||
else:
|
||||
unit += char
|
||||
if unit == '':
|
||||
unit = 'x'
|
||||
newlabel = ' '.join(words[0:-1])
|
||||
|
||||
newitem= Item(listofitems_id=listid, label=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
|
||||
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 == '':
|
||||
unit = 'x'
|
||||
|
||||
newlabel=newlabel.title()
|
||||
newitem=Item(listofitems_id=listid, label=newlabel)
|
||||
if unit:
|
||||
newitem.unit = unit
|
||||
if quantity:
|
||||
@@ -75,6 +108,7 @@ def items_append(listid):
|
||||
icon_names.append(os.path.splitext(i)[0])
|
||||
|
||||
return render_template("items_append.html", user=current_user,
|
||||
listid=listid,
|
||||
items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(),
|
||||
icons = icon_names,
|
||||
iconpath = '/'+ICONPATH,
|
||||
@@ -89,10 +123,11 @@ def item_delete(itemid):
|
||||
db.session.delete(i)
|
||||
db.session.commit()
|
||||
Log.info(f'User {current_user.id} deleted item {itemid}')
|
||||
return render_template("items_append.html", user=current_user,
|
||||
items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(),
|
||||
iconpath = '/'+ICONPATH,
|
||||
logo_url=url_for("items.items", listid=listid))
|
||||
# return render_template("items_append.html", user=current_user,
|
||||
# items=Item.query.filter_by(listofitems_id=listid).order_by(Item.label).all(),
|
||||
# iconpath = '/'+ICONPATH,
|
||||
# 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
|
||||
@items_bp.route("/items_clean/<listid>")
|
||||
|
||||
Reference in New Issue
Block a user