From c9ad415f13a2c25cf6f5621b75df56899d9ba381 Mon Sep 17 00:00:00 2001 From: aronwk-aaron Date: Sat, 28 Oct 2023 00:27:17 -0500 Subject: [PATCH] add sanity checks for inventory to stop crashing --- app/reports.py | 20 +++++++++++++++---- .../partials/charxml/_inv_grid.html.j2 | 2 +- .../partials/charxml/_item_tooltip.html.j2 | 7 ++++--- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/app/reports.py b/app/reports.py index db830b0..7aa42e5 100644 --- a/app/reports.py +++ b/app/reports.py @@ -236,13 +236,25 @@ def gen_item_report(): if "i" in inv.keys() and type(inv["i"]) == list and (int(inv["attr_t"]) == 0 or int(inv["attr_t"]) == 1): for item in inv["i"]: if item["attr_l"] in report_data: - report_data[item["attr_l"]]["item_count"] = report_data[item["attr_l"]]["item_count"] + int(item["attr_c"]) + if ("attr_c" in item): + report_data[item["attr_l"]]["item_count"] = report_data[item["attr_l"]]["item_count"] + int(item["attr_c"]) + else: + report_data[item["attr_l"]]["item_count"] = report_data[item["attr_l"]]["item_count"] + 1 else: - report_data[item["attr_l"]] = {"item_count": int(item["attr_c"]), "chars": {}} + if ("attr_c" in item): + report_data[item["attr_l"]] = {"item_count": int(item["attr_c"]), "chars": {}} + else: + report_data[item["attr_l"]] = {"item_count": 1, "chars": {}} if name in report_data[item["attr_l"]]["chars"]: - report_data[item["attr_l"]]["chars"][name] = report_data[item["attr_l"]]["chars"][name] + int(item["attr_c"]) + if ("attr_c" in item): + report_data[item["attr_l"]]["chars"][name] = report_data[item["attr_l"]]["chars"][name] + int(item["attr_c"]) + else: + report_data[item["attr_l"]]["chars"][name] = report_data[item["attr_l"]]["chars"][name] + 1 else: - report_data[item["attr_l"]]["chars"][name] = int(item["attr_c"]) + if ("attr_c" in item): + report_data[item["attr_l"]]["chars"][name] = int(item["attr_c"]) + else: + report_data[item["attr_l"]]["chars"][name] = 1 except Exception as e: current_app.logger.error(f"REPORT::ITEMS - ERROR PARSING CHARACTER {char_xml.id}") current_app.logger.error(f"REPORT::ITEMS - {e}") diff --git a/app/templates/partials/charxml/_inv_grid.html.j2 b/app/templates/partials/charxml/_inv_grid.html.j2 index fca858c..60600b5 100644 --- a/app/templates/partials/charxml/_inv_grid.html.j2 +++ b/app/templates/partials/charxml/_inv_grid.html.j2 @@ -11,7 +11,7 @@ data-placement="left" title="{% include 'partials/charxml/_item_tooltip.html.j2' %}" > - {% if inv_item.attr_c != "1" %} + {% if 'attr_c' in inv_item %} {%if inv_item.attr_c|int > 999 %} +999 diff --git a/app/templates/partials/charxml/_item_tooltip.html.j2 b/app/templates/partials/charxml/_item_tooltip.html.j2 index 46a165f..1a9721a 100644 --- a/app/templates/partials/charxml/_item_tooltip.html.j2 +++ b/app/templates/partials/charxml/_item_tooltip.html.j2 @@ -66,7 +66,8 @@ {% endwith %} {% endif %} -{%if inv_item.attr_c|int > 999 %} -
Count: {{ inv_item.attr_c|numberFormat }} +{% if 'attr_c' in inv_item %} + {%if inv_item.attr_c|int > 999 %} +
Count: {{ inv_item.attr_c|numberFormat }} + {% endif %} {% endif %} -