summaryrefslogtreecommitdiff
path: root/yaksh/middleware/user_time_zone.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2016-05-27 12:32:21 +0530
committerPrabhu Ramachandran2016-05-27 12:32:21 +0530
commit033d116bc803fe165cbe6f7e228c29d8f0b019a9 (patch)
tree6553297f4855810eb349916a4a5947a1f88c4fb2 /yaksh/middleware/user_time_zone.py
parent5c74697b00ea08a2b78615637d8b322410fca4b0 (diff)
parent7b762b4550f08b95c1ebf8196bd79c3f77a306ca (diff)
downloadonline_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.tar.gz
online_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.tar.bz2
online_test-033d116bc803fe165cbe6f7e228c29d8f0b019a9.zip
Merge pull request #99 from adityacp/fix_timezone
Fix 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..f1aace9
--- /dev/null
+++ b/yaksh/middleware/user_time_zone.py
@@ -0,0 +1,15 @@
+import pytz
+
+from django.utils import timezone
+
+
+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'))