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
9e4b0ab4
Commit
9e4b0ab4
authored
Jan 24, 2015
by
Braden MacDonald
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up some of the components
parent
3d01658f
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
83 additions
and
77 deletions
+83
-77
mentoring/components/choice.py
+4
-23
mentoring/components/common.py
+60
-0
mentoring/components/mcq.py
+3
-3
mentoring/components/message.py
+3
-19
mentoring/components/mrq.py
+3
-3
mentoring/components/templates/html/choice.html
+1
-1
mentoring/components/templates/html/mcqblock_choices.html
+1
-1
mentoring/components/templates/html/mcqblock_rating.html
+1
-1
mentoring/components/templates/html/mrqblock_choices.html
+1
-1
mentoring/components/templates/html/tip_choice_group.html
+2
-2
mentoring/components/tip.py
+4
-23
No files found.
mentoring/components/choice.py
View file @
9e4b0ab4
...
@@ -23,36 +23,17 @@
...
@@ -23,36 +23,17 @@
# Imports ###########################################################
# Imports ###########################################################
from
xblock.core
import
XBlock
from
.common
import
BlockWithContent
from
xblock.fields
import
Scope
,
String
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Classes ###########################################################
# Classes ###########################################################
class
ChoiceBlock
(
XBlock
):
class
ChoiceBlock
(
BlockWithContent
):
"""
"""
Custom choice of an answer for a MCQ/MRQ
Custom choice of an answer for a MCQ/MRQ
"""
"""
TEMPLATE
=
'templates/html/choice.html'
value
=
String
(
help
=
"Value of the choice when selected"
,
scope
=
Scope
.
content
,
default
=
""
)
value
=
String
(
help
=
"Value of the choice when selected"
,
scope
=
Scope
.
content
,
default
=
""
)
content
=
String
(
help
=
"Human-readable version of the choice value"
,
scope
=
Scope
.
content
,
default
=
""
)
content
=
String
(
help
=
"Human-readable version of the choice value"
,
scope
=
Scope
.
content
,
default
=
""
)
has_children
=
True
def
render
(
self
):
"""
Returns a fragment containing the formatted choice
"""
fragment
=
Fragment
()
child_content
=
u""
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
child_fragment
=
child
.
render
(
'mentoring_view'
,
{})
fragment
.
add_frag_resources
(
child_fragment
)
child_content
+=
child_fragment
.
content
fragment
.
add_content
(
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/choice.html'
,
{
'self'
:
self
,
'child_content'
:
child_content
,
}))
return
fragment
# TODO: fragment_text_rewriting
mentoring/components/common.py
0 → 100644
View file @
9e4b0ab4
# -*- coding: utf-8 -*-
#
# Copyright (C) 2015 OpenCraft
#
# This software's license gives you freedom; you can copy, convey,
# propagate, redistribute and/or modify this program under the terms of
# the GNU Affero General Public License (AGPL) as published by the Free
# Software Foundation (FSF), either version 3 of the License, or (at your
# option) any later version of the AGPL published by the FSF.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero
# General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program in a file in the toplevel directory called
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
# Imports ###########################################################
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Classes ###########################################################
class
BlockWithContent
(
XBlock
):
"""
A block that can contain simple text content OR <html> blocks
with rich HTML content.
"""
TEMPLATE
=
None
# Override in subclass
content
=
String
(
help
=
"Content"
,
scope
=
Scope
.
content
,
default
=
""
)
has_children
=
True
def
fallback_view
(
self
,
view_name
,
context
=
None
):
"""
Returns a fragment containing the HTML
"""
fragment
=
Fragment
()
child_content
=
u""
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
child_fragment
=
child
.
render
(
'mentoring_view'
,
{})
fragment
.
add_frag_resources
(
child_fragment
)
child_content
+=
child_fragment
.
content
fragment
.
add_content
(
ResourceLoader
(
__name__
)
.
render_template
(
self
.
TEMPLATE
,
{
'self'
:
self
,
'content'
:
self
.
content
,
'child_content'
:
child_content
,
}))
return
fragment
# TODO: fragment_text_rewriting
def
get_html
(
self
):
""" Render as HTML - not as a Fragment """
return
self
.
fallback_view
(
None
,
None
)
.
content
mentoring/components/mcq.py
View file @
9e4b0ab4
...
@@ -53,15 +53,15 @@ class MCQBlock(QuestionnaireAbstractBlock):
...
@@ -53,15 +53,15 @@ class MCQBlock(QuestionnaireAbstractBlock):
log
.
debug
(
u'Received MCQ submission: "
%
s"'
,
submission
)
log
.
debug
(
u'Received MCQ submission: "
%
s"'
,
submission
)
correct
=
True
correct
=
True
tips_
fragments
=
[]
tips_
html
=
[]
for
tip
in
self
.
get_tips
():
for
tip
in
self
.
get_tips
():
correct
=
correct
and
self
.
is_tip_correct
(
tip
,
submission
)
correct
=
correct
and
self
.
is_tip_correct
(
tip
,
submission
)
if
submission
in
tip
.
display_with_defaults
:
if
submission
in
tip
.
display_with_defaults
:
tips_
fragments
.
append
(
tip
.
render
())
tips_
html
.
append
(
tip
.
get_html
())
formatted_tips
=
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/tip_choice_group.html'
,
{
formatted_tips
=
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/tip_choice_group.html'
,
{
'self'
:
self
,
'self'
:
self
,
'tips_
fragments'
:
tips_fragments
,
'tips_
html'
:
tips_html
,
'completed'
:
correct
,
'completed'
:
correct
,
})
})
...
...
mentoring/components/message.py
View file @
9e4b0ab4
...
@@ -25,33 +25,17 @@
...
@@ -25,33 +25,17 @@
from
xblock.core
import
XBlock
from
.common
import
BlockWithContent
from
xblock.fields
import
Scope
,
String
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Classes ###########################################################
# Classes ###########################################################
class
MentoringMessageBlock
(
XBlock
):
class
MentoringMessageBlock
(
BlockWithContent
):
"""
"""
A message which can be conditionally displayed at the mentoring block level,
A message which can be conditionally displayed at the mentoring block level,
for example upon completion of the block
for example upon completion of the block
"""
"""
TEMPLATE
=
'templates/html/message.html'
content
=
String
(
help
=
"Message to display upon completion"
,
scope
=
Scope
.
content
,
default
=
""
)
content
=
String
(
help
=
"Message to display upon completion"
,
scope
=
Scope
.
content
,
default
=
""
)
type
=
String
(
help
=
"Type of message"
,
scope
=
Scope
.
content
,
default
=
"completed"
)
type
=
String
(
help
=
"Type of message"
,
scope
=
Scope
.
content
,
default
=
"completed"
)
has_children
=
True
def
mentoring_view
(
self
,
context
=
None
):
fragment
=
Fragment
()
child_content
=
u""
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
child_fragment
=
child
.
render
(
'mentoring_view'
,
context
)
fragment
.
add_frag_resources
(
child_fragment
)
child_content
+=
child_fragment
.
content
fragment
.
add_content
(
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/message.html'
,
{
'self'
:
self
,
'child_content'
:
child_content
,
}))
return
fragment
mentoring/components/mrq.py
View file @
9e4b0ab4
...
@@ -52,11 +52,11 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -52,11 +52,11 @@ class MRQBlock(QuestionnaireAbstractBlock):
results
=
[]
results
=
[]
for
choice
in
self
.
custom_choices
:
for
choice
in
self
.
custom_choices
:
choice_completed
=
True
choice_completed
=
True
choice_tips_
fragments
=
[]
choice_tips_
html
=
[]
choice_selected
=
choice
.
value
in
submissions
choice_selected
=
choice
.
value
in
submissions
for
tip
in
self
.
get_tips
():
for
tip
in
self
.
get_tips
():
if
choice
.
value
in
tip
.
display_with_defaults
:
if
choice
.
value
in
tip
.
display_with_defaults
:
choice_tips_
fragments
.
append
(
tip
.
render
())
choice_tips_
html
.
append
(
tip
.
get_html
())
if
((
not
choice_selected
and
choice
.
value
in
tip
.
require_with_defaults
)
or
if
((
not
choice_selected
and
choice
.
value
in
tip
.
require_with_defaults
)
or
(
choice_selected
and
choice
.
value
in
tip
.
reject_with_defaults
)):
(
choice_selected
and
choice
.
value
in
tip
.
reject_with_defaults
)):
...
@@ -74,7 +74,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -74,7 +74,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
choice_result
[
'completed'
]
=
choice_completed
choice_result
[
'completed'
]
=
choice_completed
choice_result
[
'tips'
]
=
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/tip_choice_group.html'
,
{
choice_result
[
'tips'
]
=
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/tip_choice_group.html'
,
{
'self'
:
self
,
'self'
:
self
,
'tips_
fragments'
:
choice_tips_fragments
,
'tips_
html'
:
choice_tips_html
,
'completed'
:
choice_completed
,
'completed'
:
choice_completed
,
})
})
...
...
mentoring/components/templates/html/choice.html
View file @
9e4b0ab4
<span
class=
"choice-text"
>
<span
class=
"choice-text"
>
{
% if self.content %}{{ self.content }}{% endif %
}
{
{ self.content }
}
{{ child_content|safe }}
{{ child_content|safe }}
</span>
</span>
mentoring/components/templates/html/mcqblock_choices.html
View file @
9e4b0ab4
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
<div
class=
"choice-result fa icon-2x"
></div>
<div
class=
"choice-result fa icon-2x"
></div>
<label
class=
"choice-label"
>
<label
class=
"choice-label"
>
<input
class=
"choice-selector"
type=
"radio"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
{%
if
self
.
student_choice =
=
choice
.
value
%}
checked
{%
endif
%}
/>
<input
class=
"choice-selector"
type=
"radio"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
{%
if
self
.
student_choice =
=
choice
.
value
%}
checked
{%
endif
%}
/>
{{ choice.
render.content
|safe }}
{{ choice.
get_html
|safe }}
</label>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
mentoring/components/templates/html/mcqblock_rating.html
View file @
9e4b0ab4
...
@@ -35,7 +35,7 @@
...
@@ -35,7 +35,7 @@
<div
class=
"choice"
>
<div
class=
"choice"
>
<div
class=
"choice-result fa icon-2x"
></div>
<div
class=
"choice-result fa icon-2x"
></div>
<label><input
type=
"radio"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
{%
if
self
.
student_choice =
=
'{{
choice
.
value
}}'
%}
checked
{%
endif
%}
/>
<label><input
type=
"radio"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
{%
if
self
.
student_choice =
=
'{{
choice
.
value
}}'
%}
checked
{%
endif
%}
/>
{{ choice.
render.content
|safe }}
{{ choice.
get_html
|safe }}
</label>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
mentoring/components/templates/html/mrqblock_choices.html
View file @
9e4b0ab4
...
@@ -11,7 +11,7 @@
...
@@ -11,7 +11,7 @@
<input
class=
"choice-selector"
type=
"checkbox"
name=
"{{ self.name }}"
<input
class=
"choice-selector"
type=
"checkbox"
name=
"{{ self.name }}"
value=
"{{ choice.value }}"
value=
"{{ choice.value }}"
{%
if
choice
.
value
in
self
.
student_choices
%}
checked
{%
endif
%}
/>
{%
if
choice
.
value
in
self
.
student_choices
%}
checked
{%
endif
%}
/>
{{ choice.
render.content
|safe }}
{{ choice.
get_html
|safe }}
</label>
</label>
<div
class=
"choice-tips"
></div>
<div
class=
"choice-tips"
></div>
</div>
</div>
...
...
mentoring/components/templates/html/tip_choice_group.html
View file @
9e4b0ab4
<div
class=
"tip-choice-group"
>
<div
class=
"tip-choice-group"
>
{% for tip_
fragment in tips_fragments
%}
{% for tip_
html in tips_html
%}
{{ tip_
fragment.body_
html|safe }}
{{ tip_html|safe }}
{% endfor %}
{% endfor %}
</div>
</div>
<div
class=
"close icon-remove-sign fa fa-times-circle"
></div>
<div
class=
"close icon-remove-sign fa fa-times-circle"
></div>
mentoring/components/tip.py
View file @
9e4b0ab4
...
@@ -23,11 +23,8 @@
...
@@ -23,11 +23,8 @@
# Imports ###########################################################
# Imports ###########################################################
from
.common
import
BlockWithContent
from
xblock.core
import
XBlock
from
xblock.fields
import
Scope
,
String
from
xblock.fields
import
Scope
,
String
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Functions #########################################################
# Functions #########################################################
...
@@ -43,34 +40,18 @@ def commas_to_set(commas_str):
...
@@ -43,34 +40,18 @@ def commas_to_set(commas_str):
# Classes ###########################################################
# Classes ###########################################################
class
TipBlock
(
XBlock
):
class
TipBlock
(
BlockWithContent
):
"""
"""
Each choice can define a tip depending on selection
Each choice can define a tip depending on selection
"""
"""
TEMPLATE
=
'templates/html/tip.html'
content
=
String
(
help
=
"Text of the tip to provide if needed"
,
scope
=
Scope
.
content
,
default
=
""
)
content
=
String
(
help
=
"Text of the tip to provide if needed"
,
scope
=
Scope
.
content
,
default
=
""
)
display
=
String
(
help
=
"List of choices to display the tip for"
,
scope
=
Scope
.
content
,
default
=
None
)
display
=
String
(
help
=
"List of choices to display the tip for"
,
scope
=
Scope
.
content
,
default
=
None
)
reject
=
String
(
help
=
"List of choices to reject"
,
scope
=
Scope
.
content
,
default
=
None
)
reject
=
String
(
help
=
"List of choices to reject"
,
scope
=
Scope
.
content
,
default
=
None
)
require
=
String
(
help
=
"List of choices to require"
,
scope
=
Scope
.
content
,
default
=
None
)
require
=
String
(
help
=
"List of choices to require"
,
scope
=
Scope
.
content
,
default
=
None
)
width
=
String
(
help
=
"Width of the tip popup"
,
scope
=
Scope
.
content
,
default
=
''
)
width
=
String
(
help
=
"Width of the tip popup"
,
scope
=
Scope
.
content
,
default
=
''
)
height
=
String
(
help
=
"Height of the tip popup"
,
scope
=
Scope
.
content
,
default
=
''
)
height
=
String
(
help
=
"Height of the tip popup"
,
scope
=
Scope
.
content
,
default
=
''
)
has_children
=
True
def
render
(
self
):
"""
Returns a fragment containing the formatted tip
"""
fragment
=
Fragment
()
child_content
=
u""
for
child_id
in
self
.
children
:
child
=
self
.
runtime
.
get_block
(
child_id
)
child_fragment
=
child
.
render
(
'mentoring_view'
,
{})
fragment
.
add_frag_resources
(
child_fragment
)
child_content
+=
child_fragment
.
content
fragment
.
add_content
(
ResourceLoader
(
__name__
)
.
render_template
(
'templates/html/tip.html'
,
{
'self'
:
self
,
'child_content'
:
child_content
,
}))
return
fragment
# TODO: fragment_text_rewriting
@property
@property
def
display_with_defaults
(
self
):
def
display_with_defaults
(
self
):
...
...
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