Merge "Revert "Fix middleware to not access session fields without user auth""

This commit is contained in:
Jenkins 2013-08-15 13:11:48 +00:00 committed by Gerrit Code Review
commit 1a6140f53d

View File

@ -46,25 +46,24 @@ class HorizonMiddleware(object):
def process_request(self, request): def process_request(self, request):
""" Adds data necessary for Horizon to function to the request. """ """ Adds data necessary for Horizon to function to the request. """
if hasattr(request, "user") and request.user.is_authenticated(): # Activate timezone handling
# Activate timezone handling tz = request.session.get('django_timezone')
tz = request.session.get('django_timezone') if tz:
if tz: timezone.activate(tz)
timezone.activate(tz)
# Check for session timeout # Check for session timeout
timeout = 1800 timeout = 1800
try: try:
timeout = settings.SESSION_TIMEOUT timeout = settings.SESSION_TIMEOUT
except AttributeError: except AttributeError:
pass pass
last_activity = request.session.get('last_activity', None) last_activity = request.session.get('last_activity', None)
timestamp = datetime.datetime.now() timestamp = datetime.datetime.now()
if last_activity and (timestamp - last_activity).seconds > timeout: if last_activity and (timestamp - last_activity).seconds > timeout:
request.session.pop('last_activity') request.session.pop('last_activity')
return HttpResponseRedirect(settings.LOGOUT_URL) return HttpResponseRedirect(settings.LOGOUT_URL)
request.session['last_activity'] = timestamp request.session['last_activity'] = timestamp
request.horizon = {'dashboard': None, request.horizon = {'dashboard': None,
'panel': None, 'panel': None,