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
efe6f231
Commit
efe6f231
authored
Sep 16, 2016
by
Jesse Shapiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor MentoringBlock to use NestedXBlock mixin
parent
88450ee0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
39 deletions
+88
-39
problem_builder/mentoring.py
+75
-14
problem_builder/message.py
+10
-0
problem_builder/questionnaire.py
+3
-2
problem_builder/templates/html/mentoring_add_buttons.html
+0
-23
No files found.
problem_builder/mentoring.py
View file @
efe6f231
...
...
@@ -34,7 +34,7 @@ from xblock.fields import Boolean, Scope, String, Integer, Float, List
from
xblock.fragment
import
Fragment
from
xblock.validation
import
ValidationMessage
from
.message
import
MentoringMessageBlock
from
.message
import
MentoringMessageBlock
,
get_message_label
from
.mixins
import
(
_normalize_id
,
QuestionMixin
,
MessageParentMixin
,
StepParentMixin
,
XBlockWithTranslationServiceMixin
)
...
...
@@ -44,9 +44,16 @@ from xblockutils.helpers import child_isinstance
from
xblockutils.resources
import
ResourceLoader
from
xblockutils.settings
import
XBlockWithSettingsMixin
,
ThemableXBlockMixin
from
xblockutils.studio_editable
import
(
NestedXBlockSpec
,
StudioEditableXBlockMixin
,
StudioContainer
XBlockMixin
,
StudioContainer
WithNestedXBlocksMixin
,
NestedXBlockSpec
,
StudioEditableXBlockMixin
,
StudioContainerWithNestedXBlocksMixin
,
)
from
problem_builder.answer
import
AnswerBlock
,
AnswerRecapBlock
from
problem_builder.mcq
import
MCQBlock
,
RatingBlock
from
problem_builder.mrq
import
MRQBlock
from
problem_builder.plot
import
PlotBlock
from
problem_builder.slider
import
SliderBlock
from
problem_builder.table
import
MentoringTableBlock
try
:
# Used to detect if we're in the workbench so we can add Font Awesome
...
...
@@ -220,7 +227,7 @@ class BaseMentoringBlock(
return
1.0
class
MentoringBlock
(
BaseMentoringBlock
,
StudioContainer
XBlock
Mixin
,
StepParentMixin
):
class
MentoringBlock
(
BaseMentoringBlock
,
StudioContainer
WithNestedXBlocks
Mixin
,
StepParentMixin
):
"""
An XBlock providing mentoring capabilities
...
...
@@ -322,6 +329,64 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
)
@property
def
allowed_nested_blocks
(
self
):
"""
Returns a list of allowed nested XBlocks. Each item can be either
* An XBlock class
* A NestedXBlockSpec
If XBlock class is used it is assumed that this XBlock is enabled and allows multiple instances.
NestedXBlockSpec allows explicitly setting disabled/enabled state, disabled reason (if any) and single/multiple
instances
"""
additional_blocks
=
[]
try
:
from
xmodule.video_module.video_module
import
VideoDescriptor
additional_blocks
.
append
(
NestedXBlockSpec
(
VideoDescriptor
,
category
=
'video'
,
label
=
_
(
u"Video"
)
))
except
ImportError
:
pass
try
:
from
imagemodal
import
ImageModal
additional_blocks
.
append
(
NestedXBlockSpec
(
ImageModal
,
category
=
'imagemodal'
,
label
=
_
(
u"Image Modal"
)
))
except
ImportError
:
pass
message_block_shims
=
[
NestedXBlockSpec
(
MentoringMessageBlock
,
category
=
'pb-message'
,
boilerplate
=
message_type
,
label
=
get_message_label
(
message_type
),
)
for
message_type
in
(
'completed'
,
'incomplete'
,
'max_attempts_reached'
,
)
]
if
self
.
is_assessment
:
message_block_shims
.
append
(
NestedXBlockSpec
(
MentoringMessageBlock
,
category
=
'pb-message'
,
boilerplate
=
'on-assessment-review'
,
label
=
get_message_label
(
'on-assessment-review'
),
)
)
return
[
NestedXBlockSpec
(
AnswerBlock
,
boilerplate
=
'studio_default'
),
MCQBlock
,
RatingBlock
,
MRQBlock
,
NestedXBlockSpec
(
None
,
category
=
"html"
,
label
=
self
.
_
(
"HTML"
)),
AnswerRecapBlock
,
MentoringTableBlock
,
PlotBlock
,
SliderBlock
]
+
additional_blocks
+
message_block_shims
@property
def
is_assessment
(
self
):
""" Checks if mentoring XBlock is in assessment mode """
return
self
.
mode
==
'assessment'
...
...
@@ -817,23 +882,19 @@ class MentoringBlock(BaseMentoringBlock, StudioContainerXBlockMixin, StepParentM
"""
Add some HTML to the author view that allows authors to add child blocks.
"""
fragment
=
Fragment
(
u'<div class="mentoring">'
)
# This DIV is needed for CSS to apply to the previews
self
.
render_children
(
context
,
fragment
,
can_reorder
=
True
,
can_add
=
False
)
fragment
.
add_content
(
u'</div>'
)
# Show buttons to add review-related child blocks only in assessment mode.
fragment
.
add_content
(
loader
.
render_template
(
'templates/html/mentoring_add_buttons.html'
,
{
"show_review"
:
self
.
is_assessment
,
}))
local_context
=
context
.
copy
()
local_context
[
'author_edit_view'
]
=
True
fragment
=
super
(
MentoringBlock
,
self
)
.
author_edit_view
(
local_context
)
fragment
.
add_content
(
loader
.
render_template
(
'templates/html/mentoring_url_name.html'
,
{
"url_name"
:
self
.
url_name
'url_name'
:
self
.
url_name
}))
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/css/problem-builder.css'
))
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/css/problem-builder-edit.css'
))
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/css/problem-builder-tinymce-content.css'
))
fragment
.
add_javascript_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/js/util.js'
))
fragment
.
add_javascript_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/js/mentoring_edit.js'
))
fragment
.
initialize_js
(
'MentoringEditComponents'
)
fragment
.
add_javascript_url
(
self
.
runtime
.
local_resource_url
(
self
,
'public/js/container_edit.js'
))
fragment
.
initialize_js
(
'ProblemBuilderContainerEdit'
)
return
fragment
@staticmethod
...
...
problem_builder/message.py
View file @
efe6f231
...
...
@@ -45,6 +45,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin, XBlockWithTransla
MESSAGE_TYPES
=
{
"completed"
:
{
"display_name"
:
_
(
u"Completed"
),
"studio_label"
:
_
(
u'Message (Complete)'
),
"long_display_name"
:
_
(
u"Message shown when complete"
),
"default"
:
_
(
u"Great job!"
),
"description"
:
_
(
...
...
@@ -54,6 +55,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin, XBlockWithTransla
},
"incomplete"
:
{
"display_name"
:
_
(
u"Incomplete"
),
"studio_label"
:
_
(
u'Message (Incomplete)'
),
"long_display_name"
:
_
(
u"Message shown when incomplete"
),
"default"
:
_
(
u"Not quite! You can try again, though."
),
"description"
:
_
(
...
...
@@ -64,6 +66,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin, XBlockWithTransla
},
"max_attempts_reached"
:
{
"display_name"
:
_
(
u"Reached max. # of attempts"
),
"studio_label"
:
_
(
u'Message (Max # Attempts)'
),
"long_display_name"
:
_
(
u"Message shown when student reaches max. # of attempts"
),
"default"
:
_
(
u"Sorry, you have used up all of your allowed submissions."
),
"description"
:
_
(
...
...
@@ -74,6 +77,7 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin, XBlockWithTransla
},
"on-assessment-review"
:
{
"display_name"
:
_
(
u"Review with attempts left"
),
"studio_label"
:
_
(
u'Message (Assessment Review)'
),
"long_display_name"
:
_
(
u"Message shown during review when attempts remain"
),
"default"
:
_
(
u"Note: if you retake this assessment, only your final score counts. "
...
...
@@ -100,6 +104,8 @@ class MentoringMessageBlock(XBlock, StudioEditableXBlockMixin, XBlockWithTransla
},
}
has_author_view
=
True
content
=
String
(
display_name
=
_
(
"Message"
),
help
=
_
(
"Message to display upon completion"
),
...
...
@@ -189,3 +195,7 @@ class CompletedMentoringMessageShim(object):
class
IncompleteMentoringMessageShim
(
object
):
CATEGORY
=
'pb-message'
STUDIO_LABEL
=
_
(
"Message (Incomplete)"
)
def
get_message_label
(
type
):
return
MentoringMessageBlock
.
MESSAGE_TYPES
[
type
][
'studio_label'
]
problem_builder/questionnaire.py
View file @
efe6f231
...
...
@@ -32,7 +32,6 @@ from xblockutils.resources import ResourceLoader
from
xblockutils.studio_editable
import
StudioEditableXBlockMixin
,
StudioContainerXBlockMixin
,
XBlockWithPreviewMixin
from
.choice
import
ChoiceBlock
from
.mentoring
import
MentoringBlock
from
.message
import
MentoringMessageBlock
from
.mixins
import
QuestionMixin
,
XBlockWithTranslationServiceMixin
from
.tip
import
TipBlock
...
...
@@ -94,8 +93,10 @@ class QuestionnaireAbstractBlock(
fragment
=
Fragment
(
loader
.
render_template
(
template_path
,
context
))
# If we use local_resource_url(self, ...) the runtime may insert many identical copies
# of questionnaire.[css/js] into the DOM. So we use the mentoring block here if possible
# of questionnaire.[css/js] into the DOM. So we use the mentoring block here if possible
.
block_with_resources
=
self
.
get_parent
()
from
.mentoring
import
MentoringBlock
# We use an inline import here to avoid a circular dependency with the .mentoring module.
if
not
isinstance
(
block_with_resources
,
MentoringBlock
):
block_with_resources
=
self
fragment
.
add_css_url
(
self
.
runtime
.
local_resource_url
(
block_with_resources
,
'public/css/questionnaire.css'
))
...
...
problem_builder/templates/html/mentoring_add_buttons.html
deleted
100644 → 0
View file @
88450ee0
{% load i18n %}
<div
class=
"add-xblock-component new-component-item adding"
>
<div
class=
"new-component"
>
<h5>
{% trans "Add New Component" %}
</h5>
<ul
class=
"new-component-type"
>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-answer"
data-boilerplate=
"studio_default"
>
{% trans "Long Answer" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-mcq"
>
{% trans "Multiple Choice Question" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-rating"
>
{% trans "Rating Question" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-mrq"
>
{% trans "Multiple Response Question" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-slider"
>
{% trans "Ranged Value Slider" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"html"
>
{% trans "HTML" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-answer-recap"
>
{% trans "Long Answer Recap" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-table"
>
{% trans "Answer Recap Table" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-message"
data-boilerplate=
"completed"
>
{% trans "Message (Complete)" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-message"
data-boilerplate=
"incomplete"
>
{% trans "Message (Incomplete)" %}
</a></li>
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-message"
data-boilerplate=
"max_attempts_reached"
>
{% trans "Message (Max # Attempts)" %}
</a></li>
{% if show_review %}
<li><a
href=
"#"
class=
"single-template add-xblock-component-button"
data-category=
"pb-message"
data-boilerplate=
"on-assessment-review"
>
{% trans "Message (Assessment Review)" %}
</a></li>
{% endif %}
</ul>
</div>
</div>
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