Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
problem-builder
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
problem-builder
Commits
1d04a463
Commit
1d04a463
authored
Jul 05, 2017
by
Douglas Cerna
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added student_view_data methods to Problem Builder and MCQ blocks to export their data as JSON
parent
27e2f4ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
82 additions
and
0 deletions
+82
-0
problem_builder/mcq.py
+21
-0
problem_builder/mentoring.py
+25
-0
problem_builder/tests/unit/test_problem_builder.py
+36
-0
No files found.
problem_builder/mcq.py
View file @
1d04a463
...
@@ -167,6 +167,27 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
...
@@ -167,6 +167,27 @@ class MCQBlock(SubmittingXBlockMixin, QuestionnaireAbstractBlock):
self
.
_
(
u"A choice value listed as correct does not exist: {choice}"
)
.
format
(
choice
=
choice_name
(
val
))
self
.
_
(
u"A choice value listed as correct does not exist: {choice}"
)
.
format
(
choice
=
choice_name
(
val
))
)
)
def
student_view_data
(
self
):
"""
Returns a JSON representation of the student_view of this XBlock,
retrievable from the Course Block API.
"""
return
{
'id'
:
self
.
name
,
'type'
:
self
.
CATEGORY
,
'question'
:
self
.
question
,
'message'
:
self
.
message
,
'choices'
:
[
{
'value'
:
choice
[
'value'
],
'content'
:
choice
[
'display_name'
]}
for
choice
in
self
.
human_readable_choices
],
'weight'
:
self
.
weight
,
'tips'
:
[
{
'content'
:
tip
.
content
,
'for_choices'
:
tip
.
values
}
for
tip
in
self
.
get_tips
()
],
}
class
RatingBlock
(
MCQBlock
):
class
RatingBlock
(
MCQBlock
):
"""
"""
...
...
problem_builder/mentoring.py
View file @
1d04a463
...
@@ -905,6 +905,31 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerWithNestedXBlocksMixin,
...
@@ -905,6 +905,31 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerWithNestedXBlocksMixin,
"""
"""
return
loader
.
load_scenarios_from_path
(
'templates/xml'
)
return
loader
.
load_scenarios_from_path
(
'templates/xml'
)
def
student_view_data
(
self
):
"""
Returns a JSON representation of the student_view of this XBlock,
retrievable from the Course Block API.
"""
components
=
[]
for
child_id
in
self
.
children
:
block
=
self
.
runtime
.
get_block
(
child_id
)
if
hasattr
(
block
,
'student_view_data'
):
components
.
append
(
block
.
student_view_data
())
return
{
'max_attempts'
:
self
.
max_attempts
,
'extended_feedback'
:
self
.
extended_feedback
,
'feedback_label'
:
self
.
feedback_label
,
'components'
:
components
,
'messages'
:
{
message_type
:
self
.
get_message_content
(
message_type
)
for
message_type
in
(
'completed'
,
'incomplete'
,
'max_attempts_reached'
,
)
}
}
class
MentoringWithExplicitStepsBlock
(
BaseMentoringBlock
,
StudioContainerWithNestedXBlocksMixin
):
class
MentoringWithExplicitStepsBlock
(
BaseMentoringBlock
,
StudioContainerWithNestedXBlocksMixin
):
"""
"""
...
...
problem_builder/tests/unit/test_problem_builder.py
View file @
1d04a463
...
@@ -109,6 +109,42 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
...
@@ -109,6 +109,42 @@ class TestMentoringBlock(BlockWithChildrenTestMixin, unittest.TestCase):
([
'pb-message'
]
if
block
.
is_assessment
else
[])
# Message type: "on-assessment-review"
([
'pb-message'
]
if
block
.
is_assessment
else
[])
# Message type: "on-assessment-review"
)
)
def
test_student_view_data
(
self
):
def
get_mock_components
():
child_a
=
Mock
(
spec
=
[
'student_view_data'
])
child_a
.
block_id
=
'child_a'
child_a
.
student_view_data
.
return_value
=
'child_a_json'
child_b
=
Mock
(
spec
=
[])
child_b
.
block_id
=
'child_b'
return
[
child_a
,
child_b
]
shared_data
=
{
'max_attempts'
:
3
,
'extended_feedback'
:
True
,
'feedback_label'
:
'Feedback label'
,
}
children
=
get_mock_components
()
children_by_id
=
{
child
.
block_id
:
child
for
child
in
children
}
block_data
=
{
'children'
:
children
}
block_data
.
update
(
shared_data
)
block
=
MentoringBlock
(
Mock
(),
DictFieldData
(
block_data
),
Mock
())
block
.
runtime
=
Mock
(
get_block
=
lambda
block
:
children_by_id
[
block
.
block_id
],
load_block_type
=
lambda
block
:
Mock
,
id_reader
=
Mock
(
get_definition_id
=
lambda
block
:
block
,
get_block_type
=
lambda
block
:
block
),
)
expected
=
{
'components'
:
[
'child_a_json'
,
],
'messages'
:
{
'completed'
:
None
,
'incomplete'
:
None
,
'max_attempts_reached'
:
None
,
}
}
expected
.
update
(
shared_data
)
self
.
assertEqual
(
block
.
student_view_data
(),
expected
)
@ddt.ddt
@ddt.ddt
class
TestMentoringBlockTheming
(
unittest
.
TestCase
):
class
TestMentoringBlockTheming
(
unittest
.
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment