diff --git a/example/settings.py b/example/settings.py index cf9574c..b3767f1 100644 --- a/example/settings.py +++ b/example/settings.py @@ -92,5 +92,7 @@ LANGUAGES = ( ('de', 'Deutsch'), ) +REPLACEMENTSTRING = u'subst_with_ans_' + try: from local_settings import * except: pass diff --git a/questionnaire/models.py b/questionnaire/models.py index b664f7d..e232e18 100644 --- a/questionnaire/models.py +++ b/questionnaire/models.py @@ -164,7 +164,9 @@ class RunInfo(models.Model): if key in cookies: del cookies[key] else: - cookies[key] = str(value) + if type(value) == 'int': + value=str(value) + cookies[key] = value cstr = json.dumps(cookies) if len(cstr) > 512: # XXX - hard coded to match cookie length above raise Exception("Cannot set cookie. No more space in cookie jar!") diff --git a/questionnaire/views.py b/questionnaire/views.py index f1560dc..57b8097 100644 --- a/questionnaire/views.py +++ b/questionnaire/views.py @@ -315,6 +315,10 @@ def show_questionnaire(request, runinfo, errors={}): jstriggers = [] qvalues = {} alignment=4 + # initialize qvalues + for k,v in runinfo.get_cookiedict().items(): + qvalues[k] = v + for question in questions: Type = question.get_type() _qnum, _qalpha = split_numal(question.number) @@ -329,6 +333,15 @@ def show_questionnaire(request, runinfo, errors={}): 'qalpha_class' : _qalpha and (ord(_qalpha[-1]) % 2 \ and ' alodd' or ' aleven') or '', } +#If the question has a magic string surrounded by spaces that refers to an answer to a previous question, fetch the answer and replace the magic string +#To be able to fetch the cookie with the answer it has to be stored using additional checks +#At the moment it only works for english. + replacementtext=settings.REPLACEMENTSTRING + questionnumberpos=question.text.find(replacementtext) + if questionnumberpos <> -1: + questionnumber=question.text_en[questionnumberpos:].split(' ')[0].replace(replacementtext,'') + if questionnumber in qvalues.keys(): + question.text_en=question.text_en.replace(replacementtext+questionnumber,qvalues[questionnumber]) if not question.newline(): alignment = max(alignment, calc_alignment(question.text)) @@ -363,9 +376,6 @@ def show_questionnaire(request, runinfo, errors={}): if runinfo.questionset.sortid != 0: progress = get_progress(runinfo.questionset.sortid / float(total)) - # initialize qvalues - for k,v in runinfo.get_cookiedict().items(): - qvalues[k] = v if request.POST: for k,v in request.POST.items(): if k.startswith("question_"): @@ -557,6 +567,8 @@ def answer_export(questionnaire, answers=None): subject = answer.subject row = [""] * len(headings) ans = answer.split_answer() + if type(ans) == int: + ans = str(ans) for choice in ans: col = None if type(choice) == list: