make answer options configurable

This commit is contained in:
Helmut Merz 2014-05-29 11:33:35 +02:00
parent 5f81ecfed2
commit 3a6d6a7ddd
3 changed files with 62 additions and 21 deletions

View file

@ -55,6 +55,21 @@ class SurveyView(ConceptView):
if self.editable:
return 'index.html'
@Lazy
def answerOptions(self):
opts = self.adapted.answerOptions
if not opts:
opts = [
dict(value='none', label=u'No answer',
description=u'survey_value_none'),
dict(value=3, label=u'Fully applies',
description=u'survey_value_3'),
dict(value=2, label=u'', description=u'survey_value_2'),
dict(value=1, label=u'', description=u'survey_value_1'),
dict(value=0, label=u'Does not apply',
description=u'survey_value_0'),]
return opts
@Lazy
def showFeedbackText(self):
sft = self.adapted.showFeedbackText
@ -77,7 +92,6 @@ class SurveyView(ConceptView):
return False
def getTeamData(self, respManager):
#result = [myResponse]
result = []
pred = self.conceptManager.get('ismember')
if pred is None:
@ -119,6 +133,7 @@ class SurveyView(ConceptView):
if value != 'none':
uid = key[len('question_'):]
question = adapted(self.getObjectForUid(uid))
if value.isdigit():
value = int(value)
data[uid] = value
response.values[question] = value
@ -167,7 +182,8 @@ class SurveyView(ConceptView):
text = qugroup.description
info = None
if qugroup.minAnswers in (u'', None):
info = translate(_(u'Please answer all questions.'), target_language=lang)
info = translate(_(u'Please answer all questions.'),
target_language=lang)
elif qugroup.minAnswers > 0:
info = translate(_(u'Please answer at least $minAnswers questions.',
mapping=dict(minAnswers=qugroup.minAnswers)),
@ -182,10 +198,19 @@ class SurveyView(ConceptView):
self.data = Responses(self.context).load()
if self.data:
setting = self.data.get(question.uid)
noAnswer = [dict(value='none', checked=(setting == None),
radio=(not question.required))]
return noAnswer + [dict(value=i, checked=(setting == i), radio=True)
for i in reversed(range(question.answerRange))]
if setting is None:
setting = 'none'
setting = str(setting)
result = []
for opt in self.answerOptions:
value = str(opt['value'])
result.append(dict(value=value, checked=(setting == value)))
return result
#noAnswer = [dict(value='none', checked=(setting == None),
# radio=(not question.required))]
#return noAnswer + [dict(value=i, checked=(setting == i), radio=True)
# for i in reversed(range(question.answerRange))]
class SurveyCsvExport(NodeView):
@ -198,7 +223,8 @@ class SurveyCsvExport(NodeView):
@Lazy
def questions(self):
result = []
for idx1, qug in enumerate(adapted(self.virtualTargetObject).questionGroups):
for idx1, qug in enumerate(
adapted(self.virtualTargetObject).questionGroups):
for idx2, qu in enumerate(qug.questions):
result.append((idx1, idx2, qug, qu))
return result

View file

@ -39,6 +39,26 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
default=4,
required=True)
answerOptions = Records(
title=_(u'Answer Options'),
description=_(u'Values to select from with corresponding column '
u'labels and descriptions. There should be at '
u'least answer range items with numeric values.'),
default=[],
required=False)
answerOptions.column_types = [
schema.Text(__name__='value', title=u'Value',),
schema.Text(__name__='label', title=u'Label'),
schema.Text(__name__='description', title=u'Description'),]
noGrouping = schema.Bool(
title=_(u'No Grouping of Questions'),
description=_(u'The questions should be presented in a linear manner, '
u'not grouped by categories or question groups.'),
default=False,
required=False)
feedbackColumns = Records(
title=_(u'Feedback Columns'),
description=_(u'Column definitions for the results table '

View file

@ -9,6 +9,7 @@
<tal:description condition="not:feedback">
<metal:title use-macro="item/conceptMacros/conceptdescription" />
</tal:description>
<div tal:condition="feedback">
<h3 i18n:translate="">Feedback</h3>
<div tal:define="header item/adapted/feedbackHeader"
@ -44,8 +45,10 @@
</div>
<div tal:define="footer item/adapted/feedbackFooter"
tal:condition="footer"
tal:content="structure python:item.renderText(footer, 'text/restructured')" />
tal:content="structure python:
item.renderText(footer, 'text/restructured')" />
</div>
<div id="questionnaire"
tal:condition="not:feedback">
<h3 i18n:translate="">Questionnaire</h3>
@ -68,13 +71,10 @@
<span tal:content="structure infoText" />
</div>
</td>
<td style="text-align: center"
i18n:translate="">No answer</td>
<td colspan="2"
i18n:translate="">Fully applies</td>
<td colspan="2"
style="text-align: right"
i18n:translate="">Does not apply</td>
<td tal:repeat="opt item/answerOptions"
style="text-align: center"
i18n:translate=""
tal:content="opt/label" />
</tr>
<tr class="vpad"
tal:repeat="question qugroup/questions">
@ -83,16 +83,11 @@
tal:repeat="value python:item.getValues(question)">
<input type="radio"
i18n:attributes="title"
tal:condition="value/radio"
tal:attributes="
name string:question_${question/uid};
value value/value;
checked value/checked;
title string:survey_value_${value/value}" />
<span tal:condition="not:value/radio"
title="Obligatory question, must be answered"
i18n:attributes="title">***
</span>
</td>
</tr>
</tal:qugroup>