Commit dcf57dd5 by Eugeny Kolpakov Committed by GitHub

Merge pull request #165 from open-craft/ekolpakov/student_view_data_with_display_names

Student view data with display names
parents 21e21468 38407811
...@@ -26,6 +26,7 @@ Problem Builder (`problem-builder`) ...@@ -26,6 +26,7 @@ Problem Builder (`problem-builder`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `max_attempts`: (integer) Max number of allowed attempts. - `max_attempts`: (integer) Max number of allowed attempts.
- `extended_feedback`: (boolean) `true` if extended feedback is enabled for this - `extended_feedback`: (boolean) `true` if extended feedback is enabled for this
block. block.
...@@ -103,6 +104,7 @@ Step Builder (`step-builder`) ...@@ -103,6 +104,7 @@ Step Builder (`step-builder`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `title`: (string) The display name of the component. - `title`: (string) The display name of the component.
- `show_title`: (boolean) `true` if the title should be displayed. - `show_title`: (boolean) `true` if the title should be displayed.
- `weight`: (float) The weight of the problem. - `weight`: (float) The weight of the problem.
...@@ -164,6 +166,7 @@ Mentoring Step (`sb-step`) ...@@ -164,6 +166,7 @@ Mentoring Step (`sb-step`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-step"` for Mentoring Step components. - `type`: (string) Always equals `"sb-step"` for Mentoring Step components.
- `title`: (string) Step component's display name. - `title`: (string) Step component's display name.
- `show_title`: (boolean) `true` if the title should be displayed. - `show_title`: (boolean) `true` if the title should be displayed.
...@@ -187,6 +190,7 @@ Review Step (`sb-review-step`) ...@@ -187,6 +190,7 @@ Review Step (`sb-review-step`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-review-step`" for Review Step components. - `type`: (string) Always equals `"sb-review-step`" for Review Step components.
- `title`: (string) Display name of the component. - `title`: (string) Display name of the component.
- `components`: (array) A list of `student_view_data` output of all immediate - `components`: (array) A list of `student_view_data` output of all immediate
...@@ -201,6 +205,7 @@ Conditional Message component is always child of a Review Step component. ...@@ -201,6 +205,7 @@ Conditional Message component is always child of a Review Step component.
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-conditional-message"` for Conditional - `type`: (string) Always equals `"sb-conditional-message"` for Conditional
Message components. Message components.
- `content`: (string) Content of the message. May contain HTML. - `content`: (string) Content of the message. May contain HTML.
...@@ -214,6 +219,7 @@ Score Summary (`sb-review-score`) ...@@ -214,6 +219,7 @@ Score Summary (`sb-review-score`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-review-score"` for Score Summary - `type`: (string) Always equals `"sb-review-score"` for Score Summary
components. components.
...@@ -223,6 +229,7 @@ Per-Question Feedback (`sb-review-per-question-feedback`) ...@@ -223,6 +229,7 @@ Per-Question Feedback (`sb-review-per-question-feedback`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-review-per-question-feedback"` for Score - `type`: (string) Always equals `"sb-review-per-question-feedback"` for Score
Summary components. Summary components.
...@@ -232,6 +239,7 @@ Long Answer (`pb-answer`) ...@@ -232,6 +239,7 @@ Long Answer (`pb-answer`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"pb-answer"` for Long Answer components. - `type`: (string) Always equals `"pb-answer"` for Long Answer components.
- `id`: (string) Unique ID (name) of the component. - `id`: (string) Unique ID (name) of the component.
- `weight`: (float) The weight of this component. - `weight`: (float) The weight of this component.
...@@ -269,6 +277,7 @@ Multiple Choice Question (`pb-mcq`) ...@@ -269,6 +277,7 @@ Multiple Choice Question (`pb-mcq`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"pb-mcq"` for MCQ components. - `type`: (string) Always equals `"pb-mcq"` for MCQ components.
- `id`: (string) Unique ID (name) of the component. - `id`: (string) Unique ID (name) of the component.
- `question`: (string) The content of the question. - `question`: (string) The content of the question.
...@@ -320,6 +329,7 @@ Rating Question (`pb-rating`) ...@@ -320,6 +329,7 @@ Rating Question (`pb-rating`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
Identical to [MCQ questions](#multiple-choice-question-pb-mcq) except that the Identical to [MCQ questions](#multiple-choice-question-pb-mcq) except that the
`type` field always equals `"pb-rating"`. `type` field always equals `"pb-rating"`.
...@@ -342,6 +352,7 @@ Multiple Response Question (`pb-mrq`) ...@@ -342,6 +352,7 @@ Multiple Response Question (`pb-mrq`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"pb-mrq"` for Multiple Response Question - `type`: (string) Always equals `"pb-mrq"` for Multiple Response Question
components. components.
- `id`: (string) Unique ID (name) of the component. - `id`: (string) Unique ID (name) of the component.
...@@ -399,6 +410,7 @@ Ranged Value Slider (`pb-slider`) ...@@ -399,6 +410,7 @@ Ranged Value Slider (`pb-slider`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"pb-slider"` for Ranged Value Slider - `type`: (string) Always equals `"pb-slider"` for Ranged Value Slider
components. components.
- `id`: (string) Unique ID (name) of the component. - `id`: (string) Unique ID (name) of the component.
...@@ -431,6 +443,7 @@ Completion (`pb-completion`) ...@@ -431,6 +443,7 @@ Completion (`pb-completion`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"pb-completion"` for Completion components. - `type`: (string) Always equals `"pb-completion"` for Completion components.
- `id`: (string) Unique ID (name) of the component. - `id`: (string) Unique ID (name) of the component.
- `title`: (string) Display name of the problem. - `title`: (string) Display name of the problem.
...@@ -463,6 +476,7 @@ Plot (`sb-plot`) ...@@ -463,6 +476,7 @@ Plot (`sb-plot`)
### `student_view_data` ### `student_view_data`
- `block_id`: (string) The XBlock's usage ID. - `block_id`: (string) The XBlock's usage ID.
- `display_name`: (string) The XBlock's display name.
- `type`: (string) Always equals `"sb-plot"` for Plot components. - `type`: (string) Always equals `"sb-plot"` for Plot components.
- `title`: (string) Display name of the component. - `title`: (string) Display name of the component.
- `q1_label`: (string) Quadrant I label. - `q1_label`: (string) Quadrant I label.
......
...@@ -267,6 +267,7 @@ class AnswerBlock(SubmittingXBlockMixin, AnswerMixin, QuestionMixin, StudioEdita ...@@ -267,6 +267,7 @@ class AnswerBlock(SubmittingXBlockMixin, AnswerMixin, QuestionMixin, StudioEdita
return { return {
'id': self.name, 'id': self.name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name,
'type': self.CATEGORY, 'type': self.CATEGORY,
'weight': self.weight, 'weight': self.weight,
'question': self.question, 'question': self.question,
......
...@@ -74,8 +74,10 @@ class ChoiceBlock( ...@@ -74,8 +74,10 @@ class ChoiceBlock(
Returns a JSON representation of the student_view of this XBlock, Returns a JSON representation of the student_view of this XBlock,
retrievable from the Course Block API. retrievable from the Course Block API.
""" """
# display_name_with_default gives out correctness - not adding it here
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self._(u"Choice ({content})").format(content=self.content),
'value': self.value, 'value': self.value,
'content': self.content, 'content': self.content,
} }
......
...@@ -116,6 +116,7 @@ class CompletionBlock( ...@@ -116,6 +116,7 @@ class CompletionBlock(
return { return {
'id': self.name, 'id': self.name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
'question': self.question, 'question': self.question,
'answer': self.answer, 'answer': self.answer,
......
...@@ -177,6 +177,7 @@ class MCQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb ...@@ -177,6 +177,7 @@ class MCQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb
return { return {
'id': self.name, 'id': self.name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
'question': self.question, 'question': self.question,
'message': self.message, 'message': self.message,
......
...@@ -923,6 +923,7 @@ class MentoringBlock( ...@@ -923,6 +923,7 @@ class MentoringBlock(
components.append(block.student_view_data()) components.append(block.student_view_data())
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name,
'max_attempts': self.max_attempts, 'max_attempts': self.max_attempts,
'extended_feedback': self.extended_feedback, 'extended_feedback': self.extended_feedback,
'feedback_label': self.feedback_label, 'feedback_label': self.feedback_label,
...@@ -1272,6 +1273,7 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes ...@@ -1272,6 +1273,7 @@ class MentoringWithExplicitStepsBlock(BaseMentoringBlock, StudioContainerWithNes
return { return {
'title': self.display_name, 'title': self.display_name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name,
'show_title': self.show_title, 'show_title': self.show_title,
'weight': self.weight, 'weight': self.weight,
'extended_feedback': self.extended_feedback, 'extended_feedback': self.extended_feedback,
......
...@@ -207,6 +207,7 @@ class MRQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb ...@@ -207,6 +207,7 @@ class MRQBlock(SubmittingXBlockMixin, StudentViewUserStateMixin, QuestionnaireAb
return { return {
'id': self.name, 'id': self.name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name,
'title': self.display_name, 'title': self.display_name,
'type': self.CATEGORY, 'type': self.CATEGORY,
'weight': self.weight, 'weight': self.weight,
......
...@@ -362,6 +362,7 @@ class PlotBlock( ...@@ -362,6 +362,7 @@ class PlotBlock(
retrievable from the Course XBlock API. retrievable from the Course XBlock API.
""" """
return { return {
'display_name': self.display_name,
'type': self.CATEGORY, 'type': self.CATEGORY,
'title': self.display_name, 'title': self.display_name,
'q1_label': self.q1_label, 'q1_label': self.q1_label,
......
...@@ -128,6 +128,7 @@ class SliderBlock( ...@@ -128,6 +128,7 @@ class SliderBlock(
return { return {
'id': self.name, 'id': self.name,
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
'question': self.question, 'question': self.question,
'min_label': self.min_label, 'min_label': self.min_label,
......
...@@ -283,6 +283,7 @@ class MentoringStepBlock( ...@@ -283,6 +283,7 @@ class MentoringStepBlock(
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
'title': self.display_name_with_default, 'title': self.display_name_with_default,
'show_title': self.show_title, 'show_title': self.show_title,
......
...@@ -112,6 +112,7 @@ class ConditionalMessageBlock( ...@@ -112,6 +112,7 @@ class ConditionalMessageBlock(
def student_view_data(self, context=None): def student_view_data(self, context=None):
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
'content': self.content, 'content': self.content,
'score_condition': self.score_condition, 'score_condition': self.score_condition,
...@@ -163,6 +164,7 @@ class ScoreSummaryBlock(XBlockWithTranslationServiceMixin, XBlockWithPreviewMixi ...@@ -163,6 +164,7 @@ class ScoreSummaryBlock(XBlockWithTranslationServiceMixin, XBlockWithPreviewMixi
def student_view_data(self, context=None): def student_view_data(self, context=None):
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
} }
...@@ -217,6 +219,7 @@ class PerQuestionFeedbackBlock(XBlockWithTranslationServiceMixin, XBlockWithPrev ...@@ -217,6 +219,7 @@ class PerQuestionFeedbackBlock(XBlockWithTranslationServiceMixin, XBlockWithPrev
def student_view_data(self, context=None): def student_view_data(self, context=None):
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name_with_default,
'type': self.CATEGORY, 'type': self.CATEGORY,
} }
...@@ -314,6 +317,7 @@ class ReviewStepBlock( ...@@ -314,6 +317,7 @@ class ReviewStepBlock(
return { return {
'block_id': unicode(self.scope_ids.usage_id), 'block_id': unicode(self.scope_ids.usage_id),
'display_name': self.display_name,
'type': self.CATEGORY, 'type': self.CATEGORY,
'title': self.display_name, 'title': self.display_name,
'components': components, 'components': components,
......
...@@ -22,9 +22,13 @@ class TestMRQBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -22,9 +22,13 @@ class TestMRQBlock(BlockWithChildrenTestMixin, unittest.TestCase):
""" """
block = MRQBlock(Mock(), DictFieldData({}), Mock()) block = MRQBlock(Mock(), DictFieldData({}), Mock())
self.assertListEqual( self.assertItemsEqual(
block.student_view_data().keys(), block.student_view_data().keys(),
['hide_results', 'tips', 'block_id', 'weight', 'title', 'question', 'message', 'type', 'id', 'choices']) [
'hide_results', 'tips', 'block_id', 'display_name',
'weight', 'title', 'question', 'message', 'type', 'id', 'choices'
]
)
@ddt.ddt @ddt.ddt
...@@ -139,7 +143,8 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -139,7 +143,8 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
} }
children = get_mock_components() children = get_mock_components()
children_by_id = {child.block_id: child for child in children} children_by_id = {child.block_id: child for child in children}
block_data = {'children': children} display_name = "I'm problem builder"
block_data = {'display_name': display_name, 'children': children}
block_data.update(shared_data) block_data.update(shared_data)
block = MentoringBlock(Mock(usage_id=1), DictFieldData(block_data), Mock(usage_id=1)) block = MentoringBlock(Mock(usage_id=1), DictFieldData(block_data), Mock(usage_id=1))
block.runtime = Mock( block.runtime = Mock(
...@@ -149,6 +154,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -149,6 +154,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
) )
expected = { expected = {
'block_id': '1', 'block_id': '1',
'display_name': display_name,
'components': [ 'components': [
'child_a_json', 'child_a_json',
], ],
......
...@@ -14,9 +14,14 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -14,9 +14,14 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
def test_student_view_data(self): def test_student_view_data(self):
blocks_by_id = {} blocks_by_id = {}
services_mocks = {
"i18n": Mock(ugettext=lambda string: string)
}
mock_runtime = Mock( mock_runtime = Mock(
get_block=lambda block_id: blocks_by_id[block_id], get_block=lambda block_id: blocks_by_id[block_id],
load_block_type=lambda block: block.__class__, load_block_type=lambda block: block.__class__,
service=lambda _, service_id: services_mocks.get(service_id),
id_reader=Mock( id_reader=Mock(
get_definition_id=lambda block_id: block_id, get_definition_id=lambda block_id: block_id,
get_block_type=lambda block_id: blocks_by_id[block_id], get_block_type=lambda block_id: blocks_by_id[block_id],
...@@ -90,6 +95,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -90,6 +95,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
expected = { expected = {
'block_id': u'1', 'block_id': u'1',
'display_name': step_builder_data['display_name'],
'title': step_builder_data['display_name'], 'title': step_builder_data['display_name'],
'show_title': step_builder_data['show_title'], 'show_title': step_builder_data['show_title'],
'weight': step_builder_data['weight'], 'weight': step_builder_data['weight'],
...@@ -99,6 +105,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -99,6 +105,7 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
{ {
'block_id': '2', 'block_id': '2',
'type': 'sb-step', 'type': 'sb-step',
'display_name': step_data['display_name'],
'title': step_data['display_name'], 'title': step_data['display_name'],
'show_title': step_data['show_title'], 'show_title': step_data['show_title'],
'next_button_label': step_data['next_button_label'], 'next_button_label': step_data['next_button_label'],
...@@ -108,14 +115,17 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase): ...@@ -108,14 +115,17 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
{ {
'block_id': '3', 'block_id': '3',
'type': 'sb-review-step', 'type': 'sb-review-step',
'display_name': review_step_data['display_name'],
'title': review_step_data['display_name'], 'title': review_step_data['display_name'],
'components': [ 'components': [
{ {
'block_id': '4', 'block_id': '4',
'display_name': "Score Summary",
'type': 'sb-review-score', 'type': 'sb-review-score',
}, },
{ {
'block_id': '5', 'block_id': '5',
'display_name': "Conditional Message",
'type': 'sb-conditional-message', 'type': 'sb-conditional-message',
'content': conditional_message_data['content'], 'content': conditional_message_data['content'],
'score_condition': conditional_message_data['score_condition'], 'score_condition': conditional_message_data['score_condition'],
......
...@@ -97,6 +97,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlockWithTranslationServiceMixin, XBl ...@@ -97,6 +97,7 @@ class TipBlock(StudioEditableXBlockMixin, XBlockWithTranslationServiceMixin, XBl
def student_view_data(self, context=None): def student_view_data(self, context=None):
return { return {
'display_name': self.display_name_with_default,
'content': self.content, 'content': self.content,
'for_choices': self.values, 'for_choices': self.values,
} }
......
...@@ -71,7 +71,7 @@ BLOCKS = [ ...@@ -71,7 +71,7 @@ BLOCKS = [
setup( setup(
name='xblock-problem-builder', name='xblock-problem-builder',
version='2.7.4', version='2.7.5',
description='XBlock - Problem Builder', description='XBlock - Problem Builder',
packages=find_packages(), packages=find_packages(),
install_requires=[ install_requires=[
......
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