2025-09-09 12:00:29 +02:00
|
|
|
import threading
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Thread-local storage for current user
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-09 12:00:29 +02:00
|
|
|
_local = threading.local()
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# set_current_user()
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-09 12:00:29 +02:00
|
|
|
def set_current_user(user):
|
2025-09-12 13:04:04 +02:00
|
|
|
"""Store the current user in thread-local storage."""
|
2025-09-09 12:00:29 +02:00
|
|
|
_local.user = user
|
|
|
|
|
2025-09-12 13:04:04 +02:00
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# get_current_user()
|
|
|
|
# ---------------------------------------------------------------------------
|
2025-09-09 12:00:29 +02:00
|
|
|
def get_current_user():
|
2025-09-12 13:04:04 +02:00
|
|
|
"""Retrieve the current user from thread-local storage (or None)."""
|
2025-09-09 12:00:29 +02:00
|
|
|
return getattr(_local, "user", None)
|