|
41 | 41 | from xblockutils.resources import ResourceLoader |
42 | 42 | from xblockutils.settings import ThemableXBlockMixin, XBlockWithSettingsMixin |
43 | 43 |
|
44 | | -from .utils import DummyTranslationService, _ |
| 44 | +from .utils import DummyTranslationService, _, remove_markdown_and_html_tags |
45 | 45 |
|
46 | 46 | try: |
47 | 47 | # pylint: disable=import-error, bad-option-value, ungrouped-imports |
@@ -840,6 +840,41 @@ def generate_report_data(self, user_state_iterator, limit_responses=None): |
840 | 840 | count += 1 |
841 | 841 | yield (user_state.username, report) |
842 | 842 |
|
| 843 | + def index_dictionary(self): |
| 844 | + """ |
| 845 | + Return dictionary prepared with module content and type for indexing. |
| 846 | + """ |
| 847 | + # return key/value fields in a Python dict object |
| 848 | + # values may be numeric / string or dict |
| 849 | + # default implementation is an empty dict |
| 850 | + xblock_body = super(PollBlock, self).index_dictionary() |
| 851 | + answers = { |
| 852 | + "option_{}".format(answer_i): remove_markdown_and_html_tags(answer[1]['label']) |
| 853 | + for answer_i, answer in enumerate(self.answers) |
| 854 | + if len(answer) == 2 and 'label' in answer[1] and answer[1]['label'] |
| 855 | + } |
| 856 | + image_alt_text = { |
| 857 | + "image_alt_{}".format(answer_i): answer[1]['img_alt'] |
| 858 | + for answer_i, answer in enumerate(self.answers) |
| 859 | + if len(answer) == 2 and 'img_alt' in answer[1] and answer[1]['img_alt'] |
| 860 | + } |
| 861 | + |
| 862 | + index_body = { |
| 863 | + "display_name": self.display_name, |
| 864 | + "question": remove_markdown_and_html_tags(self.question), |
| 865 | + } |
| 866 | + index_body.update(answers) |
| 867 | + index_body.update(image_alt_text) |
| 868 | + |
| 869 | + if "content" in xblock_body: |
| 870 | + xblock_body["content"].update(index_body) |
| 871 | + else: |
| 872 | + xblock_body["content"] = index_body |
| 873 | + |
| 874 | + xblock_body["content_type"] = "Poll" |
| 875 | + |
| 876 | + return xblock_body |
| 877 | + |
843 | 878 |
|
844 | 879 | @XBlock.wants('settings') |
845 | 880 | @XBlock.needs('i18n') |
@@ -1357,3 +1392,44 @@ def generate_report_data(self, user_state_iterator, limit_responses=None): |
1357 | 1392 | } |
1358 | 1393 | count += 1 |
1359 | 1394 | yield (user_state.username, report) |
| 1395 | + |
| 1396 | + def index_dictionary(self): |
| 1397 | + """ |
| 1398 | + Return dictionary prepared with module content and type for indexing. |
| 1399 | + """ |
| 1400 | + # return key/value fields in a Python dict object |
| 1401 | + # values may be numeric / string or dict |
| 1402 | + # default implementation is an empty dict |
| 1403 | + xblock_body = super(SurveyBlock, self).index_dictionary() |
| 1404 | + |
| 1405 | + questions = { |
| 1406 | + "question_{}".format(question_i): remove_markdown_and_html_tags(question[1]['label']) |
| 1407 | + for question_i, question in enumerate(self.questions) |
| 1408 | + if len(question) == 2 and 'label' in question[1] and question[1]['label'] |
| 1409 | + } |
| 1410 | + answers = { |
| 1411 | + "option_{}".format(answer_i): remove_markdown_and_html_tags(answer[1]) |
| 1412 | + for answer_i, answer in enumerate(self.answers) |
| 1413 | + if len(answer) == 2 and answer[1] |
| 1414 | + } |
| 1415 | + image_alt_text = { |
| 1416 | + "image_alt_{}".format(question_i): question[1]['img_alt'] |
| 1417 | + for question_i, question in enumerate(self.questions) |
| 1418 | + if len(question) == 2 and 'img_alt' in question[1] and question[1]['img_alt'] |
| 1419 | + } |
| 1420 | + |
| 1421 | + index_body = { |
| 1422 | + "display_name": self.display_name, |
| 1423 | + } |
| 1424 | + index_body.update(questions) |
| 1425 | + index_body.update(answers) |
| 1426 | + index_body.update(image_alt_text) |
| 1427 | + |
| 1428 | + if "content" in xblock_body: |
| 1429 | + xblock_body["content"].update(index_body) |
| 1430 | + else: |
| 1431 | + xblock_body["content"] = index_body |
| 1432 | + |
| 1433 | + xblock_body["content_type"] = "Survey" |
| 1434 | + |
| 1435 | + return xblock_body |
0 commit comments