diff options
author | adityacp | 2016-05-06 23:45:16 +0530 |
---|---|---|
committer | adityacp | 2016-05-12 10:33:31 +0530 |
commit | 88db9b2451693ab832a9d8c0abcad0a452b3500d (patch) | |
tree | f26a01598055b4b58cfaec0e15916a1c7295c4cd /yaksh/middleware | |
parent | 5c74697b00ea08a2b78615637d8b322410fca4b0 (diff) | |
download | online_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.tar.gz online_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.tar.bz2 online_test-88db9b2451693ab832a9d8c0abcad0a452b3500d.zip |
display datetime as per user timezone
Diffstat (limited to 'yaksh/middleware')
-rw-r--r-- | yaksh/middleware/user_time_zone.py | 15 |
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')) |