diff --git a/questionnaire/fixtures/testQuestions.yaml b/questionnaire/fixtures/testQuestions.yaml index a7e5875..8978ca7 100644 --- a/questionnaire/fixtures/testQuestions.yaml +++ b/questionnaire/fixtures/testQuestions.yaml @@ -82,12 +82,12 @@ emailcount: 0, emailsent: !!timestamp '2009-05-16 15:05:11.775082', lastemailerror: null, - questionset: 2, + questionset: 3, random: 'test:withtags', runid: 'test:withtags', state: '', - subject: 1, - tags: 'testtag' + tags: 'testtag', + subject: 1 } model: questionnaire.runinfo pk: 2 @@ -97,12 +97,12 @@ emailcount: 0, emailsent: !!timestamp '2009-05-16 15:05:11.775082', lastemailerror: null, - questionset: 2, + questionset: 3, random: 'test:withouttags', runid: 'test:withouttags', state: '', - subject: 1, - tags: '' + tags: '', + subject: 1 } model: questionnaire.runinfo pk: 3 diff --git a/questionnaire/templates/questionnaire/questionset.html b/questionnaire/templates/questionnaire/questionset.html index 5557159..39841b8 100644 --- a/questionnaire/templates/questionnaire/questionset.html +++ b/questionnaire/templates/questionnaire/questionset.html @@ -24,8 +24,8 @@ {% if progress %}
-
- {{progress.0}}% +
+ {{progress}}%
{% endif %} diff --git a/questionnaire/tests.py b/questionnaire/tests.py index 871d23e..9a33abd 100644 --- a/questionnaire/tests.py +++ b/questionnaire/tests.py @@ -152,4 +152,40 @@ class TypeTest(TestCase): question__number=k) v = v.replace('\r', '\\r').replace('\n', '\\n') - self.assertEqual(ans.answer, v) \ No newline at end of file + self.assertEqual(ans.answer, v) + + def test070_tags(self): + c = self.client + + # the first questionset in questionnaire 2 is always shown, + # but one of its 2 questions is tagged with testtag + with_tags = c.get('/q/test:withtags/1/') + + # so we'll get two questions shown if the run is tagged + self.assertEqual(with_tags.status_code, 200) + self.assertEqual(len(with_tags.context['qlist']), 2) + + # one question, if the run is not tagged + without_tags = c.get('/q/test:withouttags/1/') + + self.assertEqual(without_tags.status_code, 200) + self.assertEqual(len(without_tags.context['qlist']), 1) + + # the second questionset is only shown if the run is tagged + with_tags = c.get('/q/test:withtags/2/') + + self.assertEqual(with_tags.status_code, 200) + self.assertEqual(len(with_tags.context['qlist']), 1) + + # meaning it'll be skipped on the untagged run + without_tags = c.get('/q/test.withouttags/2/') + + self.assertEqual(without_tags.status_code, 302) # redirect + + # the progress values of the first questionset should reflect + # the fact that in one run there's only one questionset + with_tags = c.get('/q/test:withtags/1/') + without_tags = c.get('/q/test:withouttags/1/') + + self.assertEqual(with_tags.context['progress'], 50) + self.assertEqual(without_tags.context['progress'], 100) \ No newline at end of file diff --git a/questionnaire/views.py b/questionnaire/views.py index 45f9d11..915c436 100644 --- a/questionnaire/views.py +++ b/questionnaire/views.py @@ -320,14 +320,6 @@ def questionnaire(request, runcode=None, qs=None): transaction.commit() return redirect_to_qs(runinfo) - -def get_progress(percent): - "Based on a percentage as a float, calculate percentage needed for CSS progress bar" - if int(percent) >= 1: - return 100, "1" - pc = "-%s" % (120 - int(percent * 120) + 1) - return (int(percent * 100), pc) - def get_total_questionsets(runinfo): "Returns the total of visible questionsets" sets = runinfo.questionset.questionnaire.questionsets() @@ -437,7 +429,11 @@ def show_questionnaire(request, runinfo, errors={}): if not all((pos, total)): progress = None else: - progress = get_progress(float(pos) / float(total)) + progress = float(pos) / float(total) * 100.00 + + # progress is always at least one percent + progress = progress > 1.0 and int(progress) or 1 + if request.POST: for k,v in request.POST.items():