blob: 206c08a46926f9c57818f95a3f06f1ff05f7d5ca (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
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 'Asia/Kolkata'
is activated
"""
def process_request(self, request):
user = request.user
user_tz = 'Asia/Kolkata'
if hasattr(user, 'profile'):
if user.profile.timezone:
user_tz = user.profile.timezone
timezone.activate(pytz.timezone(user_tz))
|