diff options
author | Jack Morgan <jack.morgan@intel.com> | 2016-08-22 14:13:24 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@172.30.200.206> | 2016-08-22 14:13:24 +0000 |
commit | 33ec3fd340127c0aad9635fd06ac1959a6aec5f3 (patch) | |
tree | 5ee14933ba18f06bf125652516a09f870908f0e5 /tools/pharos-dashboard/account/middleware.py | |
parent | c121ae90322dac5cf72e98450c89ff7e5131b20c (diff) | |
parent | 66eb4d851e63d20031502ec0c96aaabe34c6fd32 (diff) |
Merge "Implement periodic tasks"
Diffstat (limited to 'tools/pharos-dashboard/account/middleware.py')
-rw-r--r-- | tools/pharos-dashboard/account/middleware.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/tools/pharos-dashboard/account/middleware.py b/tools/pharos-dashboard/account/middleware.py index f5170baa..6f7cac7a 100644 --- a/tools/pharos-dashboard/account/middleware.py +++ b/tools/pharos-dashboard/account/middleware.py @@ -1,7 +1,8 @@ -from django.core.exceptions import ObjectDoesNotExist from django.utils import timezone from django.utils.deprecation import MiddlewareMixin +from account.models import UserProfile + class TimezoneMiddleware(MiddlewareMixin): """ @@ -10,6 +11,12 @@ class TimezoneMiddleware(MiddlewareMixin): """ def process_request(self, request): if request.user.is_authenticated: - timezone.activate(request.user.userprofile.timezone) + try: + tz = request.user.userprofile.timezone + timezone.activate(tz) + except UserProfile.DoesNotExist: + UserProfile.objects.create(user=request.user) + tz = request.user.userprofile.timezone + timezone.activate(tz) else: timezone.deactivate() |