summaryrefslogtreecommitdiffstats
path: root/tools/pharos-dashboard/account/middleware.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pharos-dashboard/account/middleware.py')
-rw-r--r--tools/pharos-dashboard/account/middleware.py11
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()