work in progress: handling of question types

This commit is contained in:
Helmut Merz 2015-04-17 09:14:33 +02:00
parent 3470750fc7
commit 58b4db66cc
5 changed files with 68 additions and 16 deletions

View file

@ -47,6 +47,8 @@ class SurveyView(ConceptView):
batchSize = 12
teamData = None
template = template
@Lazy
def macro(self):
self.registerDojo()
@ -137,6 +139,8 @@ class SurveyView(ConceptView):
if data:
resp = Response(self.adapted, None)
for qu in self.adapted.questions:
if qu.questionType != 'value_selection':
continue
if qu.uid in data:
resp.values[qu] = data[qu.uid]
qgAvailable = True
@ -231,13 +235,16 @@ class SurveyView(ConceptView):
text = u'<i>%s</i><br />(%s)' % (text, info)
return text
def getValues(self, question):
setting = None
def loadData(self):
if self.data is None:
respManager = Responses(self.context)
respManager.personId = (self.request.form.get('person') or
respManager.getPersonId())
self.data = respManager.load()
def getValues(self, question):
setting = None
self.loadData()
if self.data:
setting = self.data.get(question.uid)
if setting is None:
@ -250,6 +257,11 @@ class SurveyView(ConceptView):
title=opt['description']))
return result
def getTextValue(self, question):
self.loadData()
if self.data:
return self.data.get(question.uid)
def getCssClass(self, question):
cls = ''
if self.errors and self.data.get(question.uid) is None:

View file

@ -26,7 +26,7 @@ from zope import interface, component, schema
from cybertools.composer.schema.grid.interfaces import Records
from cybertools.knowledge.survey import interfaces
from loops.interfaces import IConceptSchema, ILoopsAdapter
from loops.util import _
from loops.util import _, KeywordVocabulary
class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
@ -108,6 +108,16 @@ class IQuestion(IConceptSchema, interfaces.IQuestion):
""" A single question within a questionnaire.
"""
questionType = schema.Choice(
title=_(u'Question Type'),
description=_(u'Select the type of the question.'),
source=KeywordVocabulary((
('value_selection', _(u'Value Selection')),
('text', _(u'Text')),
)),
default='value_selection',
required=True)
required = schema.Bool(
title=_(u'Required'),
description=_(u'Question must be answered.'),

View file

@ -93,19 +93,10 @@
tal:content="opt/label|string:" />
</tr>
<tal:question repeat="question group/questions">
<tr tal:attributes="class python:item.getCssClass(question)">
<td tal:content="question/text" />
<td style="white-space: nowrap; text-align: center"
tal:repeat="value python:item.getValues(question)">
<input type="radio"
i18n:attributes="title"
tal:attributes="
name string:question_${question/uid};
value value/value;
checked value/checked;
title value/title" />
</td>
</tr>
<tal:question define="qutype python:
question.questionType or 'value_selection'">
<metal:question use-macro="item/template/macros/?qutype" />
</tal:question>
</tal:question>
</tal:group>
</table>
@ -119,4 +110,34 @@
</metal:block>
<metal:block define-macro="value_selection">
<tr tal:attributes="class python:item.getCssClass(question)">
<td tal:content="question/text" />
<td style="white-space: nowrap; text-align: center"
tal:repeat="value python:item.getValues(question)">
<input type="radio"
i18n:attributes="title"
tal:attributes="name string:question_${question/uid};
value value/value;
checked value/checked;
title value/title" />
</td>
</tr>
</metal:block>
<metal:block define-macro="text">
<tr tal:attributes="class python:item.getCssClass(question)">
<td>
<div tal:content="question/text" />
<textarea style="width: 90%; margin-left: 20px"
tal:content="python:item.getTextValue(question)"
tal:attributes="name string:question_${question/uid}">
</textarea>
</td>
<td tal:repeat="opt item/answerOptions" />
</tr>
</metal:block>
</html>

Binary file not shown.

View file

@ -225,6 +225,15 @@ msgstr "Mindestanzahl an Antworten"
msgid "Minumum number of questions that have to be answered. Empty means all questions have to be answered."
msgstr "Anzahl der Fragen, die mindestens beantwortet werden müssen. Keine Angabe: Es müssen alle Fragen beantwortet werden."
msgid "Question Type"
msgstr "Fragentyp"
msgid "Select the type of the question."
msgstr "Bitte den Typ der Frage auswählen."
msgid "Value Selection"
msgstr "Auswahl Bewertung"
msgid "Required"
msgstr "Pflichtfrage"