Skip to content

Commit

Permalink
Coded the use case described in #1
Browse files Browse the repository at this point in the history
  • Loading branch information
jpic committed Mar 28, 2013
1 parent 0c4e9ce commit 9e73568
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
29 changes: 29 additions & 0 deletions test_project/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends 'admin/base_site.html' %}

{% block content %}
<h2>Simulate long running request</h2>

Set an amount of seconds and focusout of this field:
<input name="seconds" />
{% endblock %}

{% block footer %}
{{ block.super }}
<script type="text/javascript">
$(document).ready(function(){
function longRunningRequest() {
$.get(
'{% url "sleep" %}',
{seconds: $('input[name=seconds]').val()},
function(data, textStatus, jqXHR) {
longRunningRequest();
}
)
}

$('input[name=seconds]').blur(function() {
longRunningRequest()
});
});
</script>
{% endblock %}
20 changes: 13 additions & 7 deletions test_project/test_project/urls.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
import time

from django.conf.urls import patterns, include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'test_project.views.home', name='home'),
# url(r'^test_project/', include('test_project.foo.urls')),
from django.contrib.auth.decorators import login_required
from django.views import generic

# Uncomment the admin/doc line below to enable admin documentation:
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
class SleepView(generic.TemplateView):
def get(self, request, *args, **kwargs):
time.sleep(int(request.GET.get('seconds', 0)))
return super(SleepView, self).get(request, *args, **kwargs)

urlpatterns = patterns('',
url(r'^$', generic.TemplateView.as_view(template_name='home.html')),
url(r'^sleep/$', login_required(
SleepView.as_view(template_name='home.html')), name='sleep'),
url(r'^admin/', include(admin.site.urls)),
url(r'session_security/', include('session_security.urls')),
)

0 comments on commit 9e73568

Please sign in to comment.