do not show questionnaire together with result; store data entered as track

This commit is contained in:
Helmut Merz 2013-03-18 17:14:19 +01:00
parent 5e8d0a8978
commit 96103b28c4
8 changed files with 101 additions and 64 deletions

View file

@ -122,4 +122,3 @@ class FeedbackItem(AdapterBase, FeedbackItem):
@property
def text(self):
return self.context.description

View file

@ -28,6 +28,7 @@ from zope.i18n import translate
from cybertools.knowledge.survey.questionnaire import Response
from loops.browser.concept import ConceptView
from loops.common import adapted
from loops.knowledge.survey.response import Responses
from loops.organize.party import getPersonForUser
from loops.util import _
@ -62,7 +63,7 @@ class SurveyView(ConceptView):
self.errors = self.check(response)
if self.errors:
return []
# TODO: store self.data in track
Responses(self.context).save(self.data)
if response is not None:
result = response.getGroupedResult()
return [dict(category=r[0].title, text=r[1].text,
@ -106,8 +107,9 @@ class SurveyView(ConceptView):
def getValues(self, question):
setting = None
# TODO: get response from track
if self.data is not None:
if self.data is None:
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))]

View file

@ -21,6 +21,15 @@
factory="loops.knowledge.survey.base.FeedbackItem"
provides="loops.knowledge.survey.interfaces.IFeedbackItem" />
<!-- track -->
<zope:class class="loops.knowledge.survey.response.Response">
<require permission="zope.View"
interface="cybertools.tracking.interfaces.ITrack" />
<require permission="zope.ManageContent"
set_schema="cybertools.tracking.interfaces.ITrack" />
</zope:class>
<!-- views -->
<zope:adapter

View file

@ -29,20 +29,35 @@ from loops.knowledge.survey.interfaces import IResponse, IResponses
from loops.organize.tracking.base import BaseRecordManager
class Responses(BaseRecordManager):
implements(IResponses)
storageName = 'survey_responses'
def __init__(self, context):
self.context = context
def save(self, data):
if not self.personId:
return
tracks = self.storage.getUserTracks(self.uid, 0, self.personId)
if tracks:
self.storage.updateTrack(tracks[0], data)
else:
self.storage.saveUserTrack(self.uid, 0, self.personId, data)
def load(self):
if self.personId:
tracks = self.storage.getUserTracks(self.uid, 0, self.personId)
if tracks:
return tracks[0].data
return {}
class Response(Track):
""" A survey response.
"""
implements(IResponse)
typeName = 'Response'
typeInterface = IResponse
class Responses(BaseRecordManager):
""" A tracking storage adapter for survey responses.
"""
implements(IResponses)
adapts(ITrackingStorage)

View file

@ -27,53 +27,60 @@
<td tal:content="fbitem/score" />
</tr>
</table>
<br />
<div class="button" id="show_questionnaire">
<a href="" onclick="back(); return false"
i18n:translate="">
Back to Questionnaire</a>
<br />
</div>
</div>
<div id="questionnaire"
tal:condition="not:feedback">
<h3 i18n:translate="">Questionnaire</h3>
<form method="post">
<table class="listing">
<tal:qugroup repeat="qugroup item/adapted/questionGroups">
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
<td tal:define="infoText python:item.getInfoText(qugroup)">
<b tal:content="qugroup/title" />
<div tal:condition="infoText">
<span tal:content="structure infoText" />
<br />&nbsp;
</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>
</tr>
<tr tal:repeat="question qugroup/questions">
<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: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>
</table>
<input type="submit" name="submit" value="Evaluate Questionnaire"
i18n:attributes="value" />
</form>
</div>
<h3 i18n:translate="">Questionnaire</h3>
<form method="post">
<table class="listing">
<tal:qugroup repeat="qugroup item/adapted/questionGroups">
<tr><td colspan="6">&nbsp;</td></tr>
<tr>
<td tal:define="infoText python:item.getInfoText(qugroup)">
<b tal:content="qugroup/title" />
<div tal:condition="infoText">
<span tal:content="structure infoText" />
<br />&nbsp;
</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>
</tr>
<tr tal:repeat="question qugroup/questions">
<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: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>
</table>
<br />
<input type="submit" name="submit" value="Evaluate Questionnaire"
i18n:attributes="value" />
</form>
</metal:block>

Binary file not shown.

View file

@ -235,6 +235,9 @@ msgstr "Trifft für unser Unternehmen voll und ganz zu"
msgid "Evaluate Questionnaire"
msgstr "Fragebogen auswerten"
msgid "Back to Questionnaire"
msgstr "Zurück zum Fragebogen"
msgid "Please answer at least $minAnswers questions."
msgstr "Bitte beantworten Sie mindestens $minAnswers Fragen."

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@ -18,8 +18,6 @@
"""
Base class(es) for track/record managers.
$Id$
"""
from zope.cachedescriptors.property import Lazy
@ -46,6 +44,10 @@ class BaseRecordManager(object):
def loopsRoot(self):
return self.context.getLoopsRoot()
@Lazy
def uid(self):
return util.getUidForObject(self.context)
@Lazy
def storage(self):
records = self.loopsRoot.getRecordManager()