result = []
if question.type == 'multiple_choice':
result.append({'key': str(question.question),
- 'values': survey_obj.prepare_result(request.cr, request.uid, question, current_filters, context=request.context)})
+ 'values': survey_obj.prepare_result(request.cr, request.uid, question, current_filters, context=request.context)['answers']
+ })
if question.type == 'simple_choice':
- result = survey_obj.prepare_result(request.cr, request.uid, question, current_filters, context=request.context)
+ result = survey_obj.prepare_result(request.cr, request.uid, question, current_filters, context=request.context)['answers']
if question.type == 'matrix':
data = survey_obj.prepare_result(request.cr, request.uid, question, current_filters, context=request.context)
for answer in data['answers']:
context = {}
#Calculate and return statistics for choice
if question.type in ['simple_choice', 'multiple_choice']:
- result_summary = {}
- [result_summary.update({label.id: {'text': label.value, 'count': 0, 'answer_id': label.id}}) for label in question.labels_ids]
+ answers = {}
+ comments = []
+ [answers.update({label.id: {'text': label.value, 'count': 0, 'answer_id': label.id}}) for label in question.labels_ids]
for input_line in question.user_input_line_ids:
- if input_line.answer_type == 'suggestion' and result_summary.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters):
- result_summary[input_line.value_suggested.id]['count'] += 1
- result_summary = result_summary.values()
+ if input_line.answer_type == 'suggestion' and answers.get(input_line.value_suggested.id) and (not(current_filters) or input_line.user_input_id.id in current_filters):
+ answers[input_line.value_suggested.id]['count'] += 1
+ if input_line.answer_type == 'text' and (not(current_filters) or input_line.user_input_id.id in current_filters):
+ comments.append(input_line)
+ result_summary = {'answers': answers.values(), 'comments': comments}
#Calculate and return statistics for matrix
if question.type == 'matrix':
rows, answers, res = {}, {}, {}
+ comments = []
[rows.update({label.id: label.value}) for label in question.labels_ids_2]
[answers.update({label.id: label.value}) for label in question.labels_ids]
for cell in product(rows.keys(), answers.keys()):
for input_line in question.user_input_line_ids:
if input_line.answer_type == 'suggestion' and (not(current_filters) or input_line.user_input_id.id in current_filters):
res[(input_line.value_suggested_row.id, input_line.value_suggested.id)] += 1
- result_summary = {'answers': answers, 'rows': rows, 'result': res}
+ if input_line.answer_type == 'text' and (not(current_filters) or input_line.user_input_id.id in current_filters):
+ comments.append(input_line)
+ result_summary = {'answers': answers, 'rows': rows, 'result': res, 'comments': comments}
#Calculate and return statistics for free_text, textbox, datetime
if question.type in ['free_text', 'textbox', 'datetime']:
<t t-call="survey.pagination" />
</template>
+ <!-- Result for comments -->
+ <template id="result_comments" name="Text Result">
+ <!-- a 'comments' variable must be set an must contain a list of browse records of user input lines -->
+ <table class="table table-hover table-condensed" t-att-id="'table_question_%d' % question.id">
+ <thead>
+ <tr>
+ <th>#</th>
+ <th>Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr t-foreach="comments" t-as="user_input">
+ <td><a t-att-href="'%s/%s' % (user_input.user_input_id.print_url, user_input.user_input_id.token)"><t t-esc="user_input_index + 1"></t></a></td>
+ <td>
+ <span t-field="user_input.value_text"></span><br/>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </template>
+
+
<!-- Result for simple_choice and multiple_choice -->
<template id="result_choice" name="Choice Result">
<div>
</tr>
</thead>
<tbody>
- <tr t-foreach="prepare_result" t-as="user_input">
+ <tr t-foreach="prepare_result['answers']" t-as="user_input">
<td>
<p t-esc="user_input['text']"></p>
</td>
</table>
</div>
</div>
+ <!-- handle comments -->
+ <div>
+ <t t-set="comments" t-value="prepare_result['comments']" />
+ <t t-if="comments">
+ <t t-call="survey.result_comments" />
+ </t>
+ </div>
+
</div>
</template>
</tbody>
</table>
</div>
+ <!-- handle comments to matrix -->
+ <div>
+ <t t-set="comments" t-value="matrix_result['comments']" />
+ <t t-if="comments">
+ <t t-call="survey.result_comments" />
+ </t>
+ </div>
</div>
</template>