From d63dd807e32cbb4f3563430e1521ac2f5029570c Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Sat, 12 Feb 2022 19:09:45 -0600 Subject: [PATCH] Handle deleted chars in pet name association Fix pre-built obj generation --- app/moderation.py | 22 +++++++++++++++------- app/properties.py | 23 ++++++++++++----------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/moderation.py b/app/moderation.py index 03de4d0..e6c421e 100644 --- a/app/moderation.py +++ b/app/moderation.py @@ -111,12 +111,17 @@ def get_pets(status="all"): """ pet_data["2"] = "Rejected" - pet_data["3"] = f""" - - {CharacterInfo.query.filter(CharacterInfo.id==pet_data['3']).first().name} - - """ + try: + pet_data["3"] = f""" + + {CharacterInfo.query.filter(CharacterInfo.id==pet_data['3']).first().name} + + """ + except Exception as e: + PetNames.query.filter(PetNames.id==id).first().delete() + pet_data["3"] = "Deleted Character" + return data @@ -128,4 +133,7 @@ def accociate_pets_and_owners(): owner = CharacterXML.query.filter(CharacterXML.xml_data.like(f"%{pet.id}%")).first() if owner: pet.owner_id = owner.id - pet.save() + pet.save() + else: + pet.delete() + diff --git a/app/properties.py b/app/properties.py index f8bdfa1..6cf8224 100644 --- a/app/properties.py +++ b/app/properties.py @@ -8,7 +8,8 @@ from flask import ( jsonify, send_from_directory, make_response, - flash + flash, + current_app ) from flask_user import login_required, current_user import json @@ -358,29 +359,29 @@ def prebuilt(content, file_format, lod): [render_component_id], one=True ) - if filename: filename = filename[0].split("\\\\")[-1].lower().split(".")[0] else: return f"No filename for LOT {content.lot}" + lxfml = pathlib.Path(f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml') if file_format == "lxfml": - lxfml = pathilob.Path(f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml') + with open(lxfml, 'r') as file: lxfml_data = file.read() - # print(lxfml_data) response = make_response(lxfml_data) elif file_format in ["obj", "mtl"]: + cache = pathlib.Path(f'app/cache/BrickModels/{filename}.lod{lod}.{file_format}') + cache.parent.mkdir(parents=True, exist_ok=True) + try: + ldd.main(str(lxfml.as_posix()), str(cache.with_suffix("").as_posix()), lod) # convert to OBJ + except Exception as e: + current_app.logger.error(f"ERROR on {cache}:\n {e}") - cache = f"app/cache/BrickModels/{filename}.lod{lod}.{file_format}" - - if not os.path.exists(cache): - lxfml = f'app/luclient/res/BrickModels/{filename.split(".")[0]}.lxfml' - ldd.main(lxfml, cache.split('.')[0]) # convert to OBJ - - with open(cache, 'r') as file: + with open(str(cache.as_posix()), 'r') as file: cache_data = file.read() + response = make_response(cache_data) else: