better handling of updating units and quantities
This commit is contained in:
@@ -30,13 +30,7 @@ def item_update(itemid, itemchecked):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
return '', 204
|
return '', 204
|
||||||
|
|
||||||
# user adds items to list
|
def interpret_and_add_item(listid, newlabel):
|
||||||
@items_bp.route("/items_append/<listid>", methods=["GET", "POST"])
|
|
||||||
@login_required
|
|
||||||
def items_append(listid):
|
|
||||||
if request.method == "POST":
|
|
||||||
# a new item has been added
|
|
||||||
newlabel = request.form["newItem"]
|
|
||||||
# could be
|
# could be
|
||||||
# appeltjes
|
# appeltjes
|
||||||
# appel goudr
|
# appel goudr
|
||||||
@@ -90,16 +84,43 @@ def items_append(listid):
|
|||||||
newlabel = ' '.join(words[2:])
|
newlabel = ' '.join(words[2:])
|
||||||
if unit == '':
|
if unit == '':
|
||||||
unit = 'x'
|
unit = 'x'
|
||||||
|
if quantity == '':
|
||||||
|
quantity = 1
|
||||||
|
|
||||||
newlabel=newlabel.title()
|
newlabel=newlabel.title()
|
||||||
newitem=Item(listofitems_id=listid, label=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:
|
||||||
|
item.quantity = quantity
|
||||||
|
item.is_suggestion = False
|
||||||
|
item.is_checked = False
|
||||||
|
else:
|
||||||
|
# create a new one
|
||||||
|
item=Item(listofitems_id=listid, label=newlabel)
|
||||||
if unit:
|
if unit:
|
||||||
newitem.unit = unit
|
item.unit = unit
|
||||||
if quantity:
|
if quantity:
|
||||||
newitem.quantity = int(quantity)
|
item.quantity = int(quantity)
|
||||||
db.session.add(newitem)
|
db.session.add(item)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
return item
|
||||||
|
|
||||||
|
|
||||||
|
# user adds items to list
|
||||||
|
@items_bp.route("/items_append/<listid>", methods=["GET", "POST"])
|
||||||
|
@login_required
|
||||||
|
def items_append(listid):
|
||||||
|
if request.method == "POST":
|
||||||
|
# a new item has been added
|
||||||
|
newlabel = request.form["newItem"]
|
||||||
|
interpret_and_add_item(listid, newlabel)
|
||||||
|
|
||||||
# read icons
|
# read icons
|
||||||
icon_names = []
|
icon_names = []
|
||||||
icon_list = os.listdir(ICONPATH)
|
icon_list = os.listdir(ICONPATH)
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ $(document).ready(function(){
|
|||||||
<a class="btn btn-{% if item.is_suggestion %}primary{% else %}info{% endif %} btn-sm" name="{{ item.id }}" onclick='handleAddOne(this);'> + </a>
|
<a class="btn btn-{% if item.is_suggestion %}primary{% else %}info{% endif %} btn-sm" name="{{ item.id }}" onclick='handleAddOne(this);'> + </a>
|
||||||
{{ item.label }}</td>
|
{{ item.label }}</td>
|
||||||
<td style="text-align: right">
|
<td style="text-align: right">
|
||||||
{% if item.quantity %}
|
{% if item.quantity > 1 or item.unit != 'x' %}
|
||||||
<a class="btn btn-outline-primary btn-sm" name="{{ item.id }}" onclick='handleAddWithQuantity(this, {{ item.quantity }} );'>{{ item.quantity }}{{ item.unit }}</a>
|
<a class="btn btn-outline-primary btn-sm" name="{{ item.id }}" onclick='handleAddWithQuantity(this, {{ item.quantity }} );'>{{ item.quantity }}{{ item.unit }}</a>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@
|
|||||||
{{ item.label }}
|
{{ item.label }}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% if item.quantity > 1 %}
|
{% if item.quantity > 1 or item.unit != 'x' %}
|
||||||
{{ item.quantity }}{{ item.unit }}
|
{{ item.quantity }}{{ item.unit }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<img src="/static/categories/{{ item.category }}.svg" style="height: 2em;" alt="...">
|
<img src="/static/categories/{{ item.category }}.svg" style="height: 2em;" alt="...">
|
||||||
|
|||||||
Reference in New Issue
Block a user