diff options
author | Magnus Hagander | 2020-04-14 13:00:35 +0000 |
---|---|---|
committer | Magnus Hagander | 2020-04-14 13:00:35 +0000 |
commit | 75bd04e991b1c5c5c18acd6c77f0facc2b740279 (patch) | |
tree | b42a4481acc943fc42ba908368f024b324910795 /postgresqleu/util/middleware.py | |
parent | b1816895690884820f18f33a7ccaec4a7718f058 (diff) |
Enforce the timezone is reset between requests
Turns out django does not reset the timezone on requests, unless it's
done explicitly. So add a new middleware that does exactly this -- and
then individual requests will set it back to the conference timezone as
required.
Not doing this could lead to very interesting results in a
multi-threaded server...
Diffstat (limited to 'postgresqleu/util/middleware.py')
-rw-r--r-- | postgresqleu/util/middleware.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/postgresqleu/util/middleware.py b/postgresqleu/util/middleware.py index 5c4bd83a..71fa743c 100644 --- a/postgresqleu/util/middleware.py +++ b/postgresqleu/util/middleware.py @@ -1,5 +1,6 @@ from django import http from django import shortcuts +from django.utils import timezone from django.conf import settings import base64 @@ -53,3 +54,15 @@ class RedirectMiddleware(object): def process_exception(self, request, exception): if isinstance(exception, RedirectException): return shortcuts.redirect(exception.url) + + +# Enforce that we deactivate the timezone before each request to make the +# thread return back to the default timezone, since django does *not* +# reset this on a per-thread basis. +class TzMiddleware(object): + def __init__(self, get_response): + self.get_response = get_response + + def __call__(self, request): + timezone.deactivate() + return self.get_response(request) |