Commit 0b0895e4 by Jonathan Piacenti

Improve event data and response display for surveys.

parent 1e409383
...@@ -49,9 +49,12 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin): ...@@ -49,9 +49,12 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin):
'max_value': 1, 'max_value': 1,
} }
) )
# The SDK doesn't set url_name.
event_dict = {'url_name': getattr(self, 'url_name', '')}
event_dict.update(choice_data)
self.publish_event_from_dict( self.publish_event_from_dict(
self.event_namespace + '.submitted', self.event_namespace + '.submitted',
choice_data, event_dict,
) )
@staticmethod @staticmethod
...@@ -466,11 +469,12 @@ class SurveyBlock(PollBase): ...@@ -466,11 +469,12 @@ class SurveyBlock(PollBase):
answer_set = OrderedDict(default_answers) answer_set = OrderedDict(default_answers)
answer_set.update(source_tally[key]) answer_set.update(source_tally[key])
tally.append({ tally.append({
'text': value['label'], 'label': value['label'],
'img': value['img'],
'answers': [ 'answers': [
{ {
'count': count, 'choice': False, 'count': count, 'choice': False,
'key': answer_key, 'top': False 'key': answer_key, 'top': False,
} }
for answer_key, count in answer_set.items()], for answer_key, count in answer_set.items()],
'key': key, 'key': key,
...@@ -625,7 +629,7 @@ class SurveyBlock(PollBase): ...@@ -625,7 +629,7 @@ class SurveyBlock(PollBase):
for key, value in self.choices.items(): for key, value in self.choices.items():
self.tally[key][value] += 1 self.tally[key][value] += 1
self.send_vote_event({'choices': choices}) self.send_vote_event({'choices': self.choices})
return result return result
......
...@@ -11,12 +11,14 @@ ...@@ -11,12 +11,14 @@
</thead> </thead>
{{#each tally}} {{#each tally}}
<tr class="survey-row"> <tr class="survey-row">
{{#if img}} <td class="survey-question">
<div class="poll-image-td"> {{#if img}}
<img src="{{img}}" /> <div class="poll-image-td">
</div> <img src="{{img}}" />
{{/if}} </div>
<td class="survey-question">{{{text}}}</td> {{/if}}
{{{label}}}
</td>
{{#each answers}} {{#each answers}}
<td class="survey-percentage survey-option{{#if choice}} survey-choice{{/if}}{{#if top}} poll-top-choice{{/if}}">{{percent}}%</td> <td class="survey-percentage survey-option{{#if choice}} survey-choice{{/if}}{{#if top}} poll-top-choice{{/if}}">{{percent}}%</td>
{{/each}} {{/each}}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment