Fix #767 -- Allow to obtain the list of orders for a question answer

This commit is contained in:
Raphael Michel
2018-04-23 11:51:28 +02:00
parent 13f29ee3ce
commit f7f151d2a9
5 changed files with 78 additions and 5 deletions

View File

@@ -416,13 +416,14 @@ class QuestionView(EventPermissionRequiredMixin, QuestionMixin, ChartContainingV
qs = [
{
'answer': ugettext('File uploaded'),
'count': qs.filter(file__isnull=False).count()
'count': qs.filter(file__isnull=False).count(),
}
]
elif self.object.type in (Question.TYPE_CHOICE, Question.TYPE_CHOICE_MULTIPLE):
qs = qs.order_by('options').values('options', 'options__answer') \
.annotate(count=Count('id')).order_by('-count')
for a in qs:
a['alink'] = a['options']
a['answer'] = str(a['options__answer'])
del a['options__answer']
elif self.object.type in (Question.TYPE_TIME, Question.TYPE_DATE, Question.TYPE_DATETIME):
@@ -430,12 +431,14 @@ class QuestionView(EventPermissionRequiredMixin, QuestionMixin, ChartContainingV
qs_model = qs
qs = qs.values('answer').annotate(count=Count('id')).order_by('-count')
for a, a_model in zip(qs, qs_model):
a['alink'] = a['answer']
a['answer'] = str(a_model)
else:
qs = qs.order_by('answer').values('answer').annotate(count=Count('id')).order_by('-count')
if self.object.type == Question.TYPE_BOOLEAN:
for a in qs:
a['alink'] = a['answer']
a['answer'] = ugettext('Yes') if a['answer'] == 'True' else ugettext('No')
a['answer_bool'] = a['answer'] == 'True'