summaryrefslogtreecommitdiff
path: root/yaksh/middleware/user_time_zone.py
diff options
context:
space:
mode:
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'))