Refactor Photo model constructor to remove timestamp parameter; update helper function to use getattr for safer attribute access.

This commit is contained in:
Yaro Kasear 2025-07-11 09:34:04 -05:00
parent e1cb99f2d1
commit 3e0faae851
3 changed files with 4 additions and 3 deletions

View file

@ -82,6 +82,6 @@ def generate_hashed_filename(file_storage, model_name: str) -> str:
def get_photo_attachable_class_by_name(name: str):
for cls in PhotoAttachable.__subclasses__():
if cls.__tablename__ == name:
if getattr(cls, '__tablename__', None) == name:
return cls
return None

View file

@ -14,6 +14,8 @@ def save_photo(file, model: str) -> str:
rel_path = generate_hashed_filename(file, model)
# Absolute path to save
assert current_app.static_folder
abs_path = os.path.join(current_app.static_folder, rel_path)
os.makedirs(os.path.dirname(abs_path), exist_ok=True)