summaryrefslogtreecommitdiffstats
path: root/pharos-dashboard/account/middleware.py
diff options
context:
space:
mode:
Diffstat (limited to 'pharos-dashboard/account/middleware.py')
-rw-r--r--pharos-dashboard/account/middleware.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/pharos-dashboard/account/middleware.py b/pharos-dashboard/account/middleware.py
index f5170ba..6f7cac7 100644
--- a/pharos-dashboard/account/middleware.py
+++ b/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()