1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from django.utils import timezone
12 from django.utils.deprecation import MiddlewareMixin
14 from account.models import UserProfile
17 class TimezoneMiddleware(MiddlewareMixin):
19 Manage user's Timezone preference.
21 Activate the timezone from request.user.userprofile if user is authenticated,
22 deactivate the timezone otherwise and use default (UTC)
25 def process_request(self, request):
26 if request.user.is_authenticated:
28 tz = request.user.userprofile.timezone
30 except UserProfile.DoesNotExist:
31 UserProfile.objects.create(user=request.user)
32 tz = request.user.userprofile.timezone