Skip to content

Commit 834bf08

Browse files
committed
Added settings to use the cache back-end for sessions. Separated out the preference cookie age from the session age. Made the session age refresh on each access, and set the session timeout to 4 weeks of no access.
- Legacy-Id: 11473
1 parent a36cf95 commit 834bf08

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

ietf/cookies/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def preferences(request, **kwargs):
3434
request.COOKIES.update(preferences)
3535
response = render("cookies/settings.html", preferences, context_instance=RequestContext(request))
3636
for key in new_cookies:
37-
response.set_cookie(key, new_cookies[key], settings.SESSION_COOKIE_AGE)
37+
response.set_cookie(key, new_cookies[key], settings.PREFERENCES_COOKIE_AGE)
3838
for key in del_cookies:
3939
response.delete_cookie(key)
4040
return response

ietf/settings.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,11 +204,19 @@ def skip_unreadable_post(record):
204204
# End logging
205205
# ------------------------------------------------------------------------
206206

207-
#SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds: 2 weeks.
208-
SESSION_COOKIE_AGE = 60 * 60 * 24 * 365 * 50 # Age of cookie, in seconds: 50 years
209207

208+
# SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 2 # Age of cookie, in seconds: 2 weeks (django default)
209+
SESSION_COOKIE_AGE = 60 * 60 * 24 * 7 * 4 # Age of cookie, in seconds: 4 weeks
210210
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
211+
# We want to use the JSON serialisation, as it's safer -- but there is /secr/
212+
# code which stashes objects in the session that can't be JSON serialized.
213+
# Switch when that code is rewritten.
214+
#SESSION_SERIALIZER = "django.contrib.sessions.serializers.JSONSerializer"
211215
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'
216+
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
217+
SESSION_SAVE_EVERY_REQUEST = True
218+
219+
PREFERENCES_COOKIE_AGE = 60 * 60 * 24 * 365 * 50 # Age of cookie, in seconds: 50 years
212220

213221
TEMPLATE_LOADERS = (
214222
('django.template.loaders.cached.Loader', (
@@ -383,6 +391,7 @@ def skip_unreadable_post(record):
383391
"*/management/commands/*",
384392
"ietf/settings*",
385393
"ietf/utils/test_runner.py",
394+
"ietf/checks.py",
386395
]
387396

388397
TEST_COVERAGE_MASTER_FILE = os.path.join(BASE_DIR, "../release-coverage.json.gz")
@@ -690,6 +699,8 @@ def skip_unreadable_post(record):
690699
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
691700
}
692701
}
702+
SESSION_ENGINE = "django.contrib.sessions.backends.db"
703+
693704
if 'SECRET_KEY' not in locals():
694705
SECRET_KEY = 'PDwXboUq!=hPjnrtG2=ge#N$Dwy+wn@uivrugwpic8mxyPfHka'
695706
ALLOWED_HOSTS = ['*',]

0 commit comments

Comments
 (0)