From 74f19611ea2958ed7102e5f28240dee5e2cf80ec Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Sat, 2 Mar 2024 03:02:37 -0500 Subject: [PATCH] Seperated Spares and added working missing table --- app.py | 4 ++- lego.py | 2 +- templates/bootstrap_table.html | 63 +++++++++++++++++++++++++++++++--- 3 files changed, 63 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 980cae2..fd73ff5 100644 --- a/app.py +++ b/app.py @@ -24,18 +24,20 @@ def save_number(tmp): data2 = request.form.get('brick.color.name') data3 = request.form.get('index') number = request.form.get('numberInput') + is_spare = request.form.get('is_spare') if number is not None: print(data1) print(data2) print(number) + print(is_spare) with open('./info/'+tmp+'.json') as info: json_file = json.loads(info.read()) print(json_file['count']) - data = '{"brick" : {"ID":"' + data1 + '","color_name": "' + data2 + '","amount":"' + number + '"}}' + data = '{"brick" : {"ID":"' + data1 + '","is_spare": "' + is_spare + '","color_name": "' + data2 + '","amount":"' + number + '"}}' json_file['unit'][int(data3)]['bricks']['missing'].append(json.loads(data)) diff --git a/lego.py b/lego.py index d039b30..24c3cc1 100644 --- a/lego.py +++ b/lego.py @@ -70,7 +70,7 @@ else: logging.error('set_img_url: ' + set_num) # set inventory -response = json.loads(rebrick.lego.get_set_elements(set_num).read()) +response = json.loads(rebrick.lego.get_set_elements(set_num,page_size=20000).read()) with open(set_path+'inventory.json', 'w', encoding='utf-8') as f: json.dump(response, f, ensure_ascii=False, indent=4) diff --git a/templates/bootstrap_table.html b/templates/bootstrap_table.html index b5512a8..269d879 100644 --- a/templates/bootstrap_table.html +++ b/templates/bootstrap_table.html @@ -1,7 +1,8 @@ {% extends "base.html" %} {% block content %} - +

Inventory

+
@@ -11,7 +12,6 @@ - {% for i in json_file['unit'] %} {% endfor %} @@ -19,6 +19,7 @@ {% for brick in inventory_file.results %} + {% if brick.is_spare == False %} @@ -27,7 +28,6 @@ - {% for i in json_file['unit'] %} + {% endfor %} + + {% endif %} + {% endfor %} + +
imgcolor.id color qtyis_spareMissing ({{ loop.index }})
{{ brick.element_id }}{{ brick.color.id }} {{ brick.color.name }} {{ brick.quantity }}{{ brick.is_spare }} @@ -36,9 +36,64 @@ + {% for j in json_file['unit'][loop.index0]['bricks']['missing'] %} {% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name %} + + {% if j['brick']['is_spare']|lower == brick.is_spare|lower %} + + {% set ns.count = j['brick']['amount'] %} + {% endif %} + {% endif %} + {% endfor %} + + +
+ +

Spares

+ + + + + + + + + + {% for i in json_file['unit'] %} + + {% endfor %} + + + + {% for brick in inventory_file.results %} + {% if brick.is_spare == True %} + + + + + + + + {% for i in json_file['unit'] %} + + {% endfor %} + {% endif %} {% endfor %}
imgelement_idpart_numnamecolorqtyMissing ({{ loop.index }})
{{ brick.element_id }}{{ brick.part.part_num }}{{ brick.part.name }}{{ brick.color.name }}{{ brick.quantity }} + {% set ns = namespace(count='') %} +
+ + + + + + {% for j in json_file['unit'][loop.index0]['bricks']['missing'] %} + {% if j['brick']['ID'] == brick.part.part_num and j['brick']['color_name'] == brick.color.name and j['brick']['is_spare']|lower == brick.is_spare|lower %} {% set ns.count = j['brick']['amount'] %} {% endif %} {% endfor %} @@ -47,8 +102,8 @@
- {% endblock %}