Adds progressbar configurations default, async and none. The configuration values are explained in the example/settings.py file
parent
a574ebc2f5
commit
9d34dcf55f
|
@ -124,7 +124,26 @@ LANGUAGES = (
|
||||||
('de', 'Deutsch'),
|
('de', 'Deutsch'),
|
||||||
)
|
)
|
||||||
|
|
||||||
REPLACEMENTSTRING = u'subst_with_ans_'
|
# Defines the progressbar behavior in the questionnaire
|
||||||
|
# the possible options are 'default', 'async' and 'none'
|
||||||
|
#
|
||||||
|
# 'default'
|
||||||
|
# The progressbar will be rendered in each questionset together with the
|
||||||
|
# questions. This is a good choice for smaller questionnaires as the
|
||||||
|
# progressbar will always be up to date.
|
||||||
|
#
|
||||||
|
# 'async'
|
||||||
|
# The progressbar value is updated using ajax once the questions have been
|
||||||
|
# rendered. This approach is the right choice for bigger questionnaires which
|
||||||
|
# result in a long time spent on updating the progressbar with each request.
|
||||||
|
# (The progress calculation is by far the most time consuming method in
|
||||||
|
# bigger questionnaires as all questionsets and questions need to be
|
||||||
|
# parsed to decide if they play a role in the current run or not)
|
||||||
|
#
|
||||||
|
# 'none'
|
||||||
|
# Completely omits the progressbar. Good if you don't want one or if the
|
||||||
|
# questionnaire is so huge that even the ajax request takes too long.
|
||||||
|
QUESTIONNAIRE_PROGRESS = 'async'
|
||||||
|
|
||||||
try: from local_settings import *
|
try: from local_settings import *
|
||||||
except: pass
|
except: pass
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
(function($){
|
||||||
|
$(document).ready(function() {
|
||||||
|
var request = {
|
||||||
|
type: 'GET',
|
||||||
|
url: progress_url,
|
||||||
|
dataType: 'json',
|
||||||
|
success: function(data) {
|
||||||
|
var progress = data.progress;
|
||||||
|
console.log(progress);
|
||||||
|
|
||||||
|
var bar = $('#progress_bar').find('.ui-progress');
|
||||||
|
bar.animate({'width': progress.toString() + '%'});
|
||||||
|
},
|
||||||
|
error: function(e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$.ajax(request);
|
||||||
|
});
|
||||||
|
})(jQuery);
|
|
@ -13,6 +13,13 @@
|
||||||
{% for x in cssinclude %}
|
{% for x in cssinclude %}
|
||||||
<link rel="stylesheet" href="{{ x }}" type="text/css" />
|
<link rel="stylesheet" href="{{ x }}" type="text/css" />
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
|
{% if async_progress %}
|
||||||
|
<script type="text/javascript">
|
||||||
|
var progress_url = "{{ async_url }}";
|
||||||
|
</script>
|
||||||
|
<script type="text/javascript" src="{{ STATIC_URL }}progress.js"></script>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block language %}
|
{% block language %}
|
||||||
|
|
|
@ -8,6 +8,8 @@ urlpatterns = patterns('',
|
||||||
questionnaire, name='questionnaire_noargs'),
|
questionnaire, name='questionnaire_noargs'),
|
||||||
url(r'^csv/(?P<qid>\d+)/',
|
url(r'^csv/(?P<qid>\d+)/',
|
||||||
export_csv, name='export_csv'),
|
export_csv, name='export_csv'),
|
||||||
|
url(r'^(?P<runcode>[^/]+)/progress',
|
||||||
|
get_async_progress, name='progress'),
|
||||||
url(r'^(?P<runcode>[^/]+)/(?P<qs>[-]{0,1}\d+)/$',
|
url(r'^(?P<runcode>[^/]+)/(?P<qs>[-]{0,1}\d+)/$',
|
||||||
questionnaire, name='questionset'),
|
questionnaire, name='questionset'),
|
||||||
url(r'^(?P<runcode>[^/]+)/',
|
url(r'^(?P<runcode>[^/]+)/',
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
from django.http import HttpResponse, HttpResponseRedirect
|
from django.http import HttpResponse, HttpResponseRedirect
|
||||||
from django.template import RequestContext
|
from django.template import RequestContext
|
||||||
from django.core.urlresolvers import reverse
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.core.cache import cache
|
||||||
from django.contrib.auth.decorators import permission_required
|
from django.contrib.auth.decorators import permission_required
|
||||||
from django.shortcuts import render_to_response, get_object_or_404
|
from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
@ -182,6 +183,15 @@ def get_progress(runinfo):
|
||||||
|
|
||||||
return int(progress)
|
return int(progress)
|
||||||
|
|
||||||
|
def get_async_progress(request, runcode):
|
||||||
|
""" Returns the progress as json for use with ajax """
|
||||||
|
|
||||||
|
runinfo = get_runinfo(runcode)
|
||||||
|
response = dict(progress=get_progress(runinfo))
|
||||||
|
|
||||||
|
cache.set('progress' + runinfo.random, response['progress'])
|
||||||
|
return HttpResponse(json.dumps(response), mimetype='application/javascript')
|
||||||
|
|
||||||
def fetch_checks(questionsets):
|
def fetch_checks(questionsets):
|
||||||
ids = [qs.pk for qs in questionsets]
|
ids = [qs.pk for qs in questionsets]
|
||||||
|
|
||||||
|
@ -487,7 +497,16 @@ def show_questionnaire(request, runinfo, errors={}):
|
||||||
|
|
||||||
qlist.append( (question, qdict) )
|
qlist.append( (question, qdict) )
|
||||||
|
|
||||||
progress = get_progress(runinfo)
|
has_progress = settings.QUESTIONNAIRE_PROGRESS in ('async', 'default')
|
||||||
|
async_progress = settings.QUESTIONNAIRE_PROGRESS == 'async'
|
||||||
|
|
||||||
|
if has_progress:
|
||||||
|
if async_progress:
|
||||||
|
progress = cache.get('progress' + runinfo.random, 1)
|
||||||
|
else:
|
||||||
|
progress = get_progress(runinfo)
|
||||||
|
else:
|
||||||
|
progress = 0
|
||||||
|
|
||||||
if request.POST:
|
if request.POST:
|
||||||
for k,v in request.POST.items():
|
for k,v in request.POST.items():
|
||||||
|
@ -509,7 +528,10 @@ def show_questionnaire(request, runinfo, errors={}):
|
||||||
triggers=jstriggers,
|
triggers=jstriggers,
|
||||||
qvalues=qvalues,
|
qvalues=qvalues,
|
||||||
jsinclude=jsinclude,
|
jsinclude=jsinclude,
|
||||||
cssinclude=cssinclude)
|
cssinclude=cssinclude,
|
||||||
|
async_progress=async_progress,
|
||||||
|
async_url=reverse('progress', args=[runinfo.random])
|
||||||
|
)
|
||||||
r['Cache-Control'] = 'no-cache'
|
r['Cache-Control'] = 'no-cache'
|
||||||
r['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT"
|
r['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT"
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in New Issue