1 from django.core.exceptions import ObjectDoesNotExist
2 from django.utils import timezone
3 from django.utils.deprecation import MiddlewareMixin
6 class TimezoneMiddleware(MiddlewareMixin):
8 Activate the timezone from request.user.userprofile if user is authenticated,
9 deactivate the timezone otherwise and use default (UTC)
11 def process_request(self, request):
12 if request.user.is_authenticated:
13 timezone.activate(request.user.userprofile.timezone)