Changeset View
Changeset View
Standalone View
Standalone View
looper/middleware.py
| Context not available. | |||||
| log = logging.getLogger(__name__) | log = logging.getLogger(__name__) | ||||
| _thread_local = threading.local() | |||||
| """Thread-local storage containing the remote addr for the current request.""" | |||||
| class RemoteAddressRecorder: | |||||
| """Store the request's remote IP address for later retrieval. | |||||
| By using this middleware, code deeper into the call stack can access | |||||
| the remote address of the request without having to pass the request | |||||
| itself to it. | |||||
| """ | |||||
| def __init__(self, get_response: typing.Callable) -> None: | |||||
| self.get_response = get_response | |||||
| def __call__(self, request): | |||||
| _thread_local.remote_addr = request.META.get('REMOTE_ADDR') or '' | |||||
| try: | |||||
| response = self.get_response(request) | |||||
| finally: | |||||
| _thread_local.remote_addr = '' | |||||
| return response | |||||
| class PreferredCurrencyMiddleware: | class PreferredCurrencyMiddleware: | ||||
| """Expose preferred currency in request.session[PREFERRED_CURRENCY_SESSION_KEY]. | """Expose preferred currency in request.session[PREFERRED_CURRENCY_SESSION_KEY]. | ||||
| Context not available. | |||||