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: if self.editable:
return 'index.html' 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 @Lazy
def showFeedbackText(self): def showFeedbackText(self):
sft = self.adapted.showFeedbackText sft = self.adapted.showFeedbackText
@ -77,7 +92,6 @@ class SurveyView(ConceptView):
return False return False
def getTeamData(self, respManager): def getTeamData(self, respManager):
#result = [myResponse]
result = [] result = []
pred = self.conceptManager.get('ismember') pred = self.conceptManager.get('ismember')
if pred is None: if pred is None:
@ -119,7 +133,8 @@ class SurveyView(ConceptView):
if value != 'none': if value != 'none':
uid = key[len('question_'):] uid = key[len('question_'):]
question = adapted(self.getObjectForUid(uid)) question = adapted(self.getObjectForUid(uid))
value = int(value) if value.isdigit():
value = int(value)
data[uid] = value data[uid] = value
response.values[question] = value response.values[question] = value
values = response.getGroupedResult() values = response.getGroupedResult()
@ -167,7 +182,8 @@ class SurveyView(ConceptView):
text = qugroup.description text = qugroup.description
info = None info = None
if qugroup.minAnswers in (u'', 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: elif qugroup.minAnswers > 0:
info = translate(_(u'Please answer at least $minAnswers questions.', info = translate(_(u'Please answer at least $minAnswers questions.',
mapping=dict(minAnswers=qugroup.minAnswers)), mapping=dict(minAnswers=qugroup.minAnswers)),
@ -182,10 +198,19 @@ class SurveyView(ConceptView):
self.data = Responses(self.context).load() self.data = Responses(self.context).load()
if self.data: if self.data:
setting = self.data.get(question.uid) setting = self.data.get(question.uid)
noAnswer = [dict(value='none', checked=(setting == None), if setting is None:
radio=(not question.required))] setting = 'none'
return noAnswer + [dict(value=i, checked=(setting == i), radio=True) setting = str(setting)
for i in reversed(range(question.answerRange))] 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): class SurveyCsvExport(NodeView):
@ -198,7 +223,8 @@ class SurveyCsvExport(NodeView):
@Lazy @Lazy
def questions(self): def questions(self):
result = [] 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): for idx2, qu in enumerate(qug.questions):
result.append((idx1, idx2, qug, qu)) result.append((idx1, idx2, qug, qu))
return result return result

View file

@ -39,6 +39,26 @@ class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
default=4, default=4,
required=True) 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( feedbackColumns = Records(
title=_(u'Feedback Columns'), title=_(u'Feedback Columns'),
description=_(u'Column definitions for the results table ' description=_(u'Column definitions for the results table '

View file

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