diff --git a/lumi2/usermanager.py b/lumi2/usermanager.py index f9c7523..8e5c2ed 100644 --- a/lumi2/usermanager.py +++ b/lumi2/usermanager.py @@ -1,6 +1,7 @@ """Views for lumi2.""" from pathlib import Path +import shutil from tempfile import TemporaryFile from json import loads, dumps, JSONDecodeError @@ -25,12 +26,17 @@ bp = Blueprint('usermanager', __name__) @bp.before_app_first_request def _init_static_images(): + """Purges and recreates the static images folder.""" + + path_to_image_cache = Path(current_app.static_folder) / "images" / "users" + if path_to_image_cache.is_dir(): + shutil.rmtree(path_to_image_cache) + path_to_image_cache.mkdir(parents=True) + conn = ldap.get_connection() - users = ldap.get_users(conn) - conn.unbind() - for user in users: + for user in ldap.get_users(conn): user._generate_static_images() - + conn.unbind() @bp.before_app_first_request diff --git a/lumi2/usermodel.py b/lumi2/usermodel.py index 3fa097f..53db474 100644 --- a/lumi2/usermodel.py +++ b/lumi2/usermodel.py @@ -388,8 +388,6 @@ class User: path_to_full_image = path_to_image_folder / "full.jpg" path_to_thumbnail = path_to_image_folder / "thumbnail.jpg" - - if not path_to_image_folder.is_dir(): path_to_image_folder.mkdir(parents=True)