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 batchSize = 12
teamData = None teamData = None
template = template
@Lazy @Lazy
def macro(self): def macro(self):
self.registerDojo() self.registerDojo()
@ -137,6 +139,8 @@ class SurveyView(ConceptView):
if data: if data:
resp = Response(self.adapted, None) resp = Response(self.adapted, None)
for qu in self.adapted.questions: for qu in self.adapted.questions:
if qu.questionType != 'value_selection':
continue
if qu.uid in data: if qu.uid in data:
resp.values[qu] = data[qu.uid] resp.values[qu] = data[qu.uid]
qgAvailable = True qgAvailable = True
@ -231,13 +235,16 @@ class SurveyView(ConceptView):
text = u'<i>%s</i><br />(%s)' % (text, info) text = u'<i>%s</i><br />(%s)' % (text, info)
return text return text
def getValues(self, question): def loadData(self):
setting = None
if self.data is None: if self.data is None:
respManager = Responses(self.context) respManager = Responses(self.context)
respManager.personId = (self.request.form.get('person') or respManager.personId = (self.request.form.get('person') or
respManager.getPersonId()) respManager.getPersonId())
self.data = respManager.load() self.data = respManager.load()
def getValues(self, question):
setting = None
self.loadData()
if self.data: if self.data:
setting = self.data.get(question.uid) setting = self.data.get(question.uid)
if setting is None: if setting is None:
@ -250,6 +257,11 @@ class SurveyView(ConceptView):
title=opt['description'])) title=opt['description']))
return result return result
def getTextValue(self, question):
self.loadData()
if self.data:
return self.data.get(question.uid)
def getCssClass(self, question): def getCssClass(self, question):
cls = '' cls = ''
if self.errors and self.data.get(question.uid) is None: 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.composer.schema.grid.interfaces import Records
from cybertools.knowledge.survey import interfaces from cybertools.knowledge.survey import interfaces
from loops.interfaces import IConceptSchema, ILoopsAdapter from loops.interfaces import IConceptSchema, ILoopsAdapter
from loops.util import _ from loops.util import _, KeywordVocabulary
class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire): class IQuestionnaire(IConceptSchema, interfaces.IQuestionnaire):
@ -108,6 +108,16 @@ class IQuestion(IConceptSchema, interfaces.IQuestion):
""" A single question within a questionnaire. """ 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( required = schema.Bool(
title=_(u'Required'), title=_(u'Required'),
description=_(u'Question must be answered.'), description=_(u'Question must be answered.'),

View file

@ -93,19 +93,10 @@
tal:content="opt/label|string:" /> tal:content="opt/label|string:" />
</tr> </tr>
<tal:question repeat="question group/questions"> <tal:question repeat="question group/questions">
<tr tal:attributes="class python:item.getCssClass(question)"> <tal:question define="qutype python:
<td tal:content="question/text" /> question.questionType or 'value_selection'">
<td style="white-space: nowrap; text-align: center" <metal:question use-macro="item/template/macros/?qutype" />
tal:repeat="value python:item.getValues(question)"> </tal: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> </tal:question>
</tal:group> </tal:group>
</table> </table>
@ -119,4 +110,34 @@
</metal:block> </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> </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." 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." 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" msgid "Required"
msgstr "Pflichtfrage" msgstr "Pflichtfrage"