fix(usermanager): rebuild static user images on startup
This commit is contained in:
parent
519cd26e13
commit
c193f1faae
@ -1,6 +1,7 @@
|
|||||||
"""Views for lumi2."""
|
"""Views for lumi2."""
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
from tempfile import TemporaryFile
|
from tempfile import TemporaryFile
|
||||||
from json import loads, dumps, JSONDecodeError
|
from json import loads, dumps, JSONDecodeError
|
||||||
|
|
||||||
@ -25,12 +26,17 @@ bp = Blueprint('usermanager', __name__)
|
|||||||
|
|
||||||
@bp.before_app_first_request
|
@bp.before_app_first_request
|
||||||
def _init_static_images():
|
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()
|
conn = ldap.get_connection()
|
||||||
users = ldap.get_users(conn)
|
for user in ldap.get_users(conn):
|
||||||
conn.unbind()
|
|
||||||
for user in users:
|
|
||||||
user._generate_static_images()
|
user._generate_static_images()
|
||||||
|
conn.unbind()
|
||||||
|
|
||||||
|
|
||||||
@bp.before_app_first_request
|
@bp.before_app_first_request
|
||||||
|
@ -388,8 +388,6 @@ class User:
|
|||||||
path_to_full_image = path_to_image_folder / "full.jpg"
|
path_to_full_image = path_to_image_folder / "full.jpg"
|
||||||
path_to_thumbnail = path_to_image_folder / "thumbnail.jpg"
|
path_to_thumbnail = path_to_image_folder / "thumbnail.jpg"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not path_to_image_folder.is_dir():
|
if not path_to_image_folder.is_dir():
|
||||||
path_to_image_folder.mkdir(parents=True)
|
path_to_image_folder.mkdir(parents=True)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user