def show_questionnaire(request, runinfo, errors={}): """ Return the QuestionSet template Also add the javascript dependency code. """ questions = runinfo.questionset.questions() total = len(runinfo.questionset.questionnaire.questionsets()) qlist = [] jsinclude = [] # js files to include cssinclude = [] # css files to include jstriggers = [] qvalues = {} alignment = 4 for question in questions: Type = question.get_type() _qnum, _qalpha = split_numal(question.number) if _qalpha: _qalpha_class = ord(_qalpha[-1]) % 2 and 'odd' or 'even' qdict = { 'template' : 'questionnaire/%s.html' % (Type), 'qnum' : _qnum, 'qalpha' : _qalpha, 'qtype' : Type, 'qnum_class' : (_qnum % 2 == 0) and " qeven" or " qodd", 'qalpha_class' : _qalpha and (ord(_qalpha[-1]) % 2 \ and ' alodd' or ' aleven') or '', } if not question.newline(): alignment = max(alignment, calc_alignment(question.text)) # add javascript dependency checks cd = question.getcheckdict() depon = cd.get('requiredif', None) or cd.get('dependent', None) if depon: # extra args to BooleanParser are not required for toString parser = BooleanParser(dep_check) qdict['checkstring'] = ' checks="%s"' % parser.toString(depon) jstriggers.append('qc_%s' % question.number) if 'default' in cd: qvalues[question.number] = cd['default'] if Type in QuestionProcessors: qdict.update(QuestionProcessors[Type](request, question)) if 'alignment' in qdict: alignment = max(alignment, qdict['alignment']) if 'jsinclude' in qdict: if qdict['jsinclude'] not in jsinclude: jsinclude.extend(qdict['jsinclude']) if 'cssinclude' in qdict: if qdict['cssinclude'] not in cssinclude: cssinclude.extend(qdict['jsinclude']) if 'jstriggers' in qdict: jstriggers.extend(qdict['jstriggers']) if 'qvalue' in qdict: qvalues[question.number] = qdict['qvalue'] qlist.append((question, qdict)) progress = None 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_"): s = k.split("_") if len(s) == 2: qvalues[s[1]] = v r = r2r("questionnaire/questionset.html", request, questionset=runinfo.questionset, runinfo=runinfo, errors=errors, qlist=qlist, progress=progress, triggers=jstriggers, qvalues=qvalues, alignment=alignment, jsinclude=jsinclude, cssinclude=cssinclude) r['Cache-Control'] = 'no-cache' r['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT" return r
def show_questionnaire(request, runinfo, errors={}): """ Return the QuestionSet template Also add the javascript dependency code. """ questions = runinfo.questionset.questions() total = len(runinfo.questionset.questionnaire.questionsets()) qlist = [] jsinclude = [] # js files to include cssinclude = [] # css files to include jstriggers = [] qvalues = {} alignment=4 for question in questions: Type = question.get_type() _qnum, _qalpha = split_numal(question.number) if _qalpha: _qalpha_class = ord(_qalpha[-1]) % 2 and 'odd' or 'even' qdict = { 'template' : 'questionnaire/%s.html' % (Type), 'qnum' : _qnum, 'qalpha' : _qalpha, 'qtype' : Type, 'qnum_class' : (_qnum % 2 == 0) and " qeven" or " qodd", 'qalpha_class' : _qalpha and (ord(_qalpha[-1]) % 2 \ and ' alodd' or ' aleven') or '', } if not question.newline(): alignment = max(alignment, calc_alignment(question.text)) # add javascript dependency checks cd = question.getcheckdict() depon = cd.get('requiredif',None) or cd.get('dependent',None) if depon: # extra args to BooleanParser are not required for toString parser = BooleanParser(dep_check) qdict['checkstring'] = ' checks="%s"' % parser.toString(depon) jstriggers.append('qc_%s' % question.number) if 'default' in cd: qvalues[question.number] = cd['default'] if Type in QuestionProcessors: qdict.update(QuestionProcessors[Type](request, question)) if 'alignment' in qdict: alignment = max(alignment, qdict['alignment']) if 'jsinclude' in qdict: if qdict['jsinclude'] not in jsinclude: jsinclude.extend(qdict['jsinclude']) if 'cssinclude' in qdict: if qdict['cssinclude'] not in cssinclude: cssinclude.extend(qdict['jsinclude']) if 'jstriggers' in qdict: jstriggers.extend(qdict['jstriggers']) if 'qvalue' in qdict: qvalues[question.number] = qdict['qvalue'] qlist.append( (question, qdict) ) progress = None 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_"): s = k.split("_") if len(s) == 2: qvalues[s[1]] = v r = r2r("questionnaire/questionset.html", request, questionset=runinfo.questionset, runinfo=runinfo, errors=errors, qlist=qlist, progress=progress, triggers=jstriggers, qvalues=qvalues, alignment=alignment, jsinclude=jsinclude, cssinclude=cssinclude) r['Cache-Control'] = 'no-cache' r['Expires'] = "Thu, 24 Jan 1980 00:00:00 GMT" return r
def show_questionnaire(request, runinfo, errors={}): """ Return the QuestionSet template Also add the javascript dependency code. """ questions = runinfo.questionset.questions() total = len(runinfo.questionset.questionnaire.questionsets()) qlist = [] jsinclude = [] # js files to include cssinclude = [] # css files to include 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) if _qalpha: _qalpha_class = ord(_qalpha[-1]) % 2 and "odd" or "even" qdict = { "template": "questionnaire/%s.html" % (Type), "qnum": _qnum, "qalpha": _qalpha, "qtype": Type, "qnum_class": (_qnum % 2 == 0) and " qeven" or " qodd", "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)) # add javascript dependency checks cd = question.getcheckdict() depon = cd.get("requiredif", None) or cd.get("dependent", None) if depon: # extra args to BooleanParser are not required for toString parser = BooleanParser(dep_check) qdict["checkstring"] = ' checks="%s"' % parser.toString(depon) jstriggers.append("qc_%s" % question.number) if "default" in cd: qvalues[question.number] = cd["default"] if Type in QuestionProcessors: qdict.update(QuestionProcessors[Type](request, question)) if "alignment" in qdict: alignment = max(alignment, qdict["alignment"]) if "jsinclude" in qdict: if qdict["jsinclude"] not in jsinclude: jsinclude.extend(qdict["jsinclude"]) if "cssinclude" in qdict: if qdict["cssinclude"] not in cssinclude: cssinclude.extend(qdict["jsinclude"]) if "jstriggers" in qdict: jstriggers.extend(qdict["jstriggers"]) if "qvalue" in qdict: qvalues[question.number] = qdict["qvalue"] qlist.append((question, qdict)) progress = None if runinfo.questionset.sortid != 0: progress = get_progress(runinfo.questionset.sortid / float(total)) if request.POST: for k, v in request.POST.items(): if k.startswith("question_"): s = k.split("_") if len(s) == 4: qvalues[s[1] + "_" + v] = "1" # evaluates true in JS elif len(s) == 3 and s[2] == "comment": qvalues[s[1] + "_" + s[2]] = v else: qvalues[s[1]] = v r = r2r( "questionnaire/questionset.html", request, questionset=runinfo.questionset, runinfo=runinfo, errors=errors, qlist=qlist, progress=progress, triggers=jstriggers, qvalues=qvalues, alignment=alignment, jsinclude=jsinclude, cssinclude=cssinclude, ) r["Cache-Control"] = "no-cache" r["Expires"] = "Thu, 24 Jan 1980 00:00:00 GMT" return r