add support for Django-1.6
Sessions now store JSON instead of pickled objects. Partially-implements blueprint django-1point6 Change-Id: I332ba18005284774a53fb3cb8c6e51bca1480ded
This commit is contained in:
parent
8db6727af5
commit
13355dacdb
@ -21,9 +21,9 @@
|
|||||||
Middleware provided and used by Horizon.
|
Middleware provided and used by Horizon.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import datetime
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import time
|
||||||
|
|
||||||
from django.conf import settings # noqa
|
from django.conf import settings # noqa
|
||||||
from django.contrib.auth import REDIRECT_FIELD_NAME # noqa
|
from django.contrib.auth import REDIRECT_FIELD_NAME # noqa
|
||||||
@ -61,7 +61,7 @@ class HorizonMiddleware(object):
|
|||||||
timeout = 1800
|
timeout = 1800
|
||||||
|
|
||||||
last_activity = request.session.get('last_activity', None)
|
last_activity = request.session.get('last_activity', None)
|
||||||
timestamp = datetime.datetime.now()
|
timestamp = int(time.time())
|
||||||
request.horizon = {'dashboard': None,
|
request.horizon = {'dashboard': None,
|
||||||
'panel': None,
|
'panel': None,
|
||||||
'async_messages': []}
|
'async_messages': []}
|
||||||
@ -98,7 +98,8 @@ class HorizonMiddleware(object):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
if last_activity and (timestamp - last_activity).seconds > timeout:
|
if (isinstance(last_activity, int)
|
||||||
|
and (timestamp - last_activity) > timeout):
|
||||||
request.session.pop('last_activity')
|
request.session.pop('last_activity')
|
||||||
response = HttpResponseRedirect(
|
response = HttpResponseRedirect(
|
||||||
'%s?next=%s' % (settings.LOGOUT_URL, request.path))
|
'%s?next=%s' % (settings.LOGOUT_URL, request.path))
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import datetime
|
import time
|
||||||
|
|
||||||
from django.conf import settings # noqa
|
from django.conf import settings # noqa
|
||||||
|
|
||||||
@ -46,8 +46,7 @@ class MiddlewareTests(test.TestCase):
|
|||||||
timeout = settings.SESSION_TIMEOUT
|
timeout = settings.SESSION_TIMEOUT
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
timeout = 1800
|
timeout = 1800
|
||||||
request.session['last_activity'] =\
|
request.session['last_activity'] = int(time.time()) - (timeout + 10)
|
||||||
datetime.datetime.now() - datetime.timedelta(seconds=timeout + 10)
|
|
||||||
mw = middleware.HorizonMiddleware()
|
mw = middleware.HorizonMiddleware()
|
||||||
resp = mw.process_request(request)
|
resp = mw.process_request(request)
|
||||||
self.assertEqual(resp.status_code, 302)
|
self.assertEqual(resp.status_code, 302)
|
||||||
|
@ -171,10 +171,15 @@ SESSION_COOKIE_HTTPONLY = True
|
|||||||
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
|
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
|
||||||
SESSION_COOKIE_SECURE = False
|
SESSION_COOKIE_SECURE = False
|
||||||
SESSION_TIMEOUT = 1800
|
SESSION_TIMEOUT = 1800
|
||||||
|
|
||||||
# When using cookie-based sessions, log error when the session cookie exceeds
|
# When using cookie-based sessions, log error when the session cookie exceeds
|
||||||
# the following size (common browsers drop cookies above a certain size):
|
# the following size (common browsers drop cookies above a certain size):
|
||||||
SESSION_COOKIE_MAX_SIZE = 4093
|
SESSION_COOKIE_MAX_SIZE = 4093
|
||||||
|
|
||||||
|
# when doing upgrades, it may be wise to stick to PickleSerializer
|
||||||
|
# TODO(mrunge): remove after Icehouse
|
||||||
|
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
|
||||||
|
|
||||||
gettext_noop = lambda s: s
|
gettext_noop = lambda s: s
|
||||||
LANGUAGES = (
|
LANGUAGES = (
|
||||||
('en', gettext_noop('English')),
|
('en', gettext_noop('English')),
|
||||||
|
Loading…
Reference in New Issue
Block a user