preferences questionnaire basically working
This commit is contained in:
parent
38d74bcb21
commit
144e6e5412
2 changed files with 108 additions and 3 deletions
|
@ -84,6 +84,10 @@ class SurveyView(InstitutionMixin, ConceptView):
|
|||
def report(self):
|
||||
return self.request.form.get('report')
|
||||
|
||||
@Lazy
|
||||
def questionnaireType(self):
|
||||
return self.adapted.questionnaireType
|
||||
|
||||
def teamReports(self):
|
||||
if self.adapted.teamBasedEvaluation:
|
||||
if checkPermission('loops.ViewRestricted', self.context):
|
||||
|
@ -99,11 +103,24 @@ class SurveyView(InstitutionMixin, ConceptView):
|
|||
@Lazy
|
||||
def groups(self):
|
||||
result = []
|
||||
if self.questionnaireType == 'pref_selection':
|
||||
groups = [g.questions for g in self.adapted.questionGroups]
|
||||
questions = []
|
||||
for idxg, g in enumerate(groups):
|
||||
qus = []
|
||||
for idxq, qu in enumerate(g):
|
||||
questions.append((idxg + 3 * idxq, qu))
|
||||
questions.sort()
|
||||
questions = [item[1] for item in questions]
|
||||
size = len(questions)
|
||||
for idx in range(0, size, 3):
|
||||
result.append(dict(title=u'Question', infoText=None,
|
||||
questions=questions[idx:idx+3]))
|
||||
return [g for g in result if len(g['questions']) == 3]
|
||||
if self.adapted.noGrouping:
|
||||
questions = list(self.adapted.questions)
|
||||
questions.sort(key=lambda x: x.title)
|
||||
size = len(questions)
|
||||
#nb, rem = divmod(size, self.batchSize)
|
||||
bs = self.batchSize
|
||||
for idx in range(0, size, bs):
|
||||
result.append(dict(title=u'Question', infoText=None,
|
||||
|
@ -207,6 +224,8 @@ class SurveyView(InstitutionMixin, ConceptView):
|
|||
if self.adapted.teamBasedEvaluation and self.institution:
|
||||
respManager.institutionId = self.getUidForObject(
|
||||
baseObject(self.institution))
|
||||
if self.adapted.questionnaireType == 'pref_selection':
|
||||
return self.prefsResults(respManager, form, action)
|
||||
data = {}
|
||||
response = Response(self.adapted, None)
|
||||
for key, value in form.items():
|
||||
|
@ -280,6 +299,22 @@ class SurveyView(InstitutionMixin, ConceptView):
|
|||
result['texts'] = '<br />'.join([unicode(t) for t in texts if t])
|
||||
return result
|
||||
|
||||
def prefsResults(self, respManager, form, action):
|
||||
result = []
|
||||
data = {}
|
||||
for key, value in form.items():
|
||||
if key.startswith('group_') and value:
|
||||
data[value] = 1
|
||||
respManager.save(data)
|
||||
if action == 'save':
|
||||
self.message = u'Your data have been saved.'
|
||||
return []
|
||||
self.data = data
|
||||
#self.errors = self.check(response)
|
||||
if self.errors:
|
||||
return []
|
||||
return result
|
||||
|
||||
def check(self, response):
|
||||
errors = []
|
||||
values = response.values
|
||||
|
@ -352,6 +387,11 @@ class SurveyView(InstitutionMixin, ConceptView):
|
|||
if self.data:
|
||||
return self.data.get(question.uid)
|
||||
|
||||
def getPrefsValue(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:
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
<metal:block define-macro="survey"
|
||||
tal:define="feedback item/results;
|
||||
questType item/questionnaireType;
|
||||
questMacro python:
|
||||
'quest_' + (questType or 'standard');
|
||||
report request/report|nothing;
|
||||
reportMacro python:
|
||||
'report_' + (report or 'standard');
|
||||
|
@ -21,9 +24,14 @@
|
|||
<div tal:condition="feedback">
|
||||
<metal:block use-macro="item/template/macros/?reportMacro" />
|
||||
</div>
|
||||
|
||||
<div id="questionnaire"
|
||||
tal:condition="not:feedback">
|
||||
<metal:block use-macro="item/template/macros/?questMacro" />
|
||||
</div>
|
||||
</metal:block>
|
||||
|
||||
|
||||
<metal:block define-macro="quest_standard">
|
||||
<tal:inst condition="item/adapted/teamBasedEvaluation">
|
||||
<metal:inst use-macro="item/knowledge_macros/select_institution" />
|
||||
</tal:inst>
|
||||
|
@ -91,7 +99,64 @@
|
|||
i18n:attributes="value"
|
||||
onclick="setRadioButtons('none'); return false" />
|
||||
</form>
|
||||
</div>
|
||||
</metal:block>
|
||||
|
||||
|
||||
<metal:block define-macro="quest_pref_selection">
|
||||
<h3 i18n:translate="">Questionnaire</h3>
|
||||
<div class="error"
|
||||
tal:condition="errors">
|
||||
<div tal:repeat="error errors">
|
||||
<span i18n:translate=""
|
||||
tal:content="error/text" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="message"
|
||||
tal:condition="message"
|
||||
i18n:translate=""
|
||||
tal:content="message" />
|
||||
<form method="post">
|
||||
<table class="listing">
|
||||
<input type="hidden" name="person"
|
||||
tal:define="personId request/person|nothing"
|
||||
tal:condition="personId"
|
||||
tal:attributes="value personId" />
|
||||
<tal:group repeat="group item/groups">
|
||||
<tr>
|
||||
<td> </td>
|
||||
<td> </td></tr>
|
||||
<tr class="vpad">
|
||||
<td tal:define="infoText group/infoText">
|
||||
<b i18n:translate=""
|
||||
tal:content="group/title" />
|
||||
<div class="infotext"
|
||||
tal:condition="infoText">
|
||||
<span tal:content="structure infoText" />
|
||||
</div>
|
||||
</td>
|
||||
<td />
|
||||
</tr>
|
||||
<tal:question repeat="question group/questions">
|
||||
<tr tal:attributes="class python:item.getCssClass(question)">
|
||||
<td tal:content="question/text" />
|
||||
<td tal:define="value python:item.getPrefsValue(question)">
|
||||
<input type="radio"
|
||||
tal:attributes="name string:group_${repeat/group/index};
|
||||
value question/uid;
|
||||
checked value" />
|
||||
</td>
|
||||
</tr>
|
||||
</tal:question>
|
||||
</tal:group>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Evaluate Questionnaire"
|
||||
i18n:attributes="value" />
|
||||
<input type="submit" name="save" value="Save Data"
|
||||
i18n:attributes="value" />
|
||||
<input type="button" name="reset_responses" value="Reset Responses Entered"
|
||||
i18n:attributes="value"
|
||||
onclick="setRadioButtons('none'); return false" />
|
||||
</form>
|
||||
</metal:block>
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue