diff options
author | Jack Morgan <jack.morgan@intel.com> | 2016-08-22 14:13:06 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-08-22 14:13:06 +0000 |
commit | c121ae90322dac5cf72e98450c89ff7e5131b20c (patch) | |
tree | 51b6c58e102777649940686915da48aab5971fac /tools/pharos-dashboard/account/middleware.py | |
parent | e4649cce49068942ef754746fdd5bc75636075de (diff) | |
parent | 3b5ef3b0a88247eeafeee878de528aad71f9fd4b (diff) |
Merge "Split the dashboard into different apps, add tests"
Diffstat (limited to 'tools/pharos-dashboard/account/middleware.py')
-rw-r--r-- | tools/pharos-dashboard/account/middleware.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/pharos-dashboard/account/middleware.py b/tools/pharos-dashboard/account/middleware.py new file mode 100644 index 00000000..f5170baa --- /dev/null +++ b/tools/pharos-dashboard/account/middleware.py @@ -0,0 +1,15 @@ +from django.core.exceptions import ObjectDoesNotExist +from django.utils import timezone +from django.utils.deprecation import MiddlewareMixin + + +class TimezoneMiddleware(MiddlewareMixin): + """ + Activate the timezone from request.user.userprofile if user is authenticated, + deactivate the timezone otherwise and use default (UTC) + """ + def process_request(self, request): + if request.user.is_authenticated: + timezone.activate(request.user.userprofile.timezone) + else: + timezone.deactivate() |