summaryrefslogtreecommitdiff
path: root/yaksh/middleware/user_time_zone.py
blob: f48bb626aac99e5359e349adcc0b709bcc33bf0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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'))