summaryrefslogtreecommitdiff
path: root/yaksh/middleware/user_time_zone.py
diff options
context:
space:
mode:
authoradityacp2016-05-06 23:45:16 +0530
committeradityacp2016-05-12 10:33:31 +0530
commit88db9b2451693ab832a9d8c0abcad0a452b3500d (patch)
treef26a01598055b4b58cfaec0e15916a1c7295c4cd /yaksh/middleware/user_time_zone.py
parent5c74697b00ea08a2b78615637d8b322410fca4b0 (diff)
downloadonline_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.tar.gz
online_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.tar.bz2
online_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.zip
display datetime as per user timezone
Diffstat (limited to 'yaksh/middleware/user_time_zone.py')
-rw-r--r--yaksh/middleware/user_time_zone.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/yaksh/middleware/user_time_zone.py b/yaksh/middleware/user_time_zone.py
new file mode 100644
index 0000000..f48bb62
--- /dev/null
+++ b/yaksh/middleware/user_time_zone.py
@@ -0,0 +1,15 @@
+import pytz
+
+from django.utils import timezone
+from yaksh.models import Profile
+
+class TimezoneMiddleware(object):
+ """ Middleware to get user's timezone and activate timezone
+ if user timezone is not available default value 'UTC' is activated """
+ def process_request(self, request):
+ user = request.user
+ if hasattr(user, 'profile'):
+ user_tz = user.profile.timezone
+ timezone.activate(pytz.timezone(user_tz))
+ else:
+ timezone.activate(pytz.timezone('UTC'))