Skip to content

Commit a578ca0

Browse files
committed
add javascript ping to keep session alive
1 parent 96ae20a commit a578ca0

File tree

6 files changed

+40
-0
lines changed

6 files changed

+40
-0
lines changed

MANIFEST.in

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.md
2+
recursive-include django-session-idle-timeout/templates *
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{% load url from future %}
2+
<script type="text/javascript">
3+
function session_keep_alive() {
4+
http_request = new XMLHttpRequest();
5+
http_request.open('GET', "{% url 'django-session-idle-timeout_ping' %}");
6+
http_request.send(null);
7+
}
8+
9+
// ping every five minutes
10+
setInterval(session_keep_alive, {{ interval }});
11+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding: UTF-8 -*-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# -*- coding: UTF-8 -*-
2+
from django import template
3+
from django.conf import settings
4+
5+
register = template.Library()
6+
7+
def session_keep_alive(context):
8+
return context.update({
9+
'interval': int(getattr(settings, 'SESSION_IDLE_TIMEOUT', 1800)) / 2 * 1000,
10+
})
11+
register.inclusion_tag('session_keep_alive.html', takes_context=True)(session_keep_alive)

django-session-idle-timeout/urls.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# -*- coding: UTF-8 -*-
2+
3+
from django.conf.urls import patterns, url
4+
import views
5+
6+
urlpatterns = patterns('',
7+
url(r"^/?", views.PingView.as_view(), name="django-session-idle-timeout_ping"),
8+
)

django-session-idle-timeout/views.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# -*- coding: UTF-8 -*-
2+
from django.views.generic import View
3+
from django.http import HttpResponse
4+
5+
class PingView(View):
6+
def get(self, request):
7+
return HttpResponse('pong')

0 commit comments

Comments
 (0)