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
dbf5365b
Commit
dbf5365b
authored
Mar 25, 2014
by
Alan Boudreault
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix LightChild fields instanciation issue
parent
522da359
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
mentoring/light_children.py
+12
-3
mentoring/mrq.py
+12
-10
No files found.
mentoring/light_children.py
View file @
dbf5365b
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
import
logging
import
logging
import
json
import
json
import
copy
from
lazy
import
lazy
from
lazy
import
lazy
...
@@ -102,6 +103,14 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
...
@@ -102,6 +103,14 @@ class LightChildrenMixin(XBlockWithChildrenFragmentsMixin):
child
=
child_class
(
block
)
child
=
child_class
(
block
)
child
.
name
=
u'{}_{}'
.
format
(
block
.
name
,
child_id
)
child
.
name
=
u'{}_{}'
.
format
(
block
.
name
,
child_id
)
# Instanciate our LightChild fields
# TODO HACK, Since we are not replacing the fields attribute with directly, we need to
# instanciate new fields for our LightChild.
fields
=
[(
attr
,
value
)
for
attr
,
value
in
child_class
.
__dict__
.
iteritems
()
if
\
isinstance
(
value
,
LightChildField
)]
for
attr
,
value
in
fields
:
child
.
__dict__
[
attr
]
=
copy
.
deepcopy
(
value
)
# Add any children the child may itself have
# Add any children the child may itself have
child_class
.
init_block_from_node
(
child
,
xml_child
,
xml_child
.
items
())
child_class
.
init_block_from_node
(
child
,
xml_child
,
xml_child
.
items
())
...
@@ -257,13 +266,13 @@ class LightChild(Plugin, LightChildrenMixin):
...
@@ -257,13 +266,13 @@ class LightChild(Plugin, LightChildrenMixin):
return
return
student_data
=
json
.
loads
(
self
.
student_data
)
student_data
=
json
.
loads
(
self
.
student_data
)
fields
=
self
.
get_fields
()
fields
=
self
.
get_fields
_to_save
()
for
field
in
fields
:
for
field
in
fields
:
if
field
in
student_data
:
if
field
in
student_data
:
setattr
(
self
,
field
,
student_data
[
field
])
setattr
(
self
,
field
,
student_data
[
field
])
@classmethod
@classmethod
def
get_fields
(
cls
):
def
get_fields
_to_save
(
cls
):
"""
"""
Returns a list of all LightChildField of the class. Used for saving student data.
Returns a list of all LightChildField of the class. Used for saving student data.
"""
"""
...
@@ -281,7 +290,7 @@ class LightChild(Plugin, LightChildrenMixin):
...
@@ -281,7 +290,7 @@ class LightChild(Plugin, LightChildrenMixin):
self
.
student_data
=
{}
self
.
student_data
=
{}
# Get All LightChild fields to save
# Get All LightChild fields to save
for
field
in
self
.
get_fields
():
for
field
in
self
.
get_fields
_to_save
():
self
.
student_data
[
field
]
=
getattr
(
self
,
field
)
.
to_json
()
self
.
student_data
[
field
]
=
getattr
(
self
,
field
)
.
to_json
()
if
self
.
name
:
if
self
.
name
:
...
...
mentoring/mrq.py
View file @
dbf5365b
...
@@ -48,7 +48,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -48,7 +48,7 @@ class MRQBlock(QuestionnaireAbstractBlock):
# TODO REMOVE THIS, ONLY NEEDED FOR LIGHTCHILDREN
# TODO REMOVE THIS, ONLY NEEDED FOR LIGHTCHILDREN
@classmethod
@classmethod
def
get_fields
(
cls
):
def
get_fields
_to_save
(
cls
):
return
[
return
[
'num_attempts'
'num_attempts'
]
]
...
@@ -57,19 +57,23 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -57,19 +57,23 @@ class MRQBlock(QuestionnaireAbstractBlock):
def
submit
(
self
,
submissions
):
def
submit
(
self
,
submissions
):
log
.
debug
(
u'Received MRQ submissions: "
%
s"'
,
submissions
)
log
.
debug
(
u'Received MRQ submissions: "
%
s"'
,
submissions
)
# Ensure our data are loaded from the db
# TODO HACK, TO REMOVE.
self
.
load_student_data
()
completed
=
True
completed
=
True
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_fragments
=
[]
choice_selected
=
choice
.
value
in
submissions
choice_selected
=
choice
.
value
.
get
()
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
.
get
()
in
tip
.
display_with_defaults
:
choice_tips_fragments
.
append
(
tip
.
render
())
choice_tips_fragments
.
append
(
tip
.
render
())
if
((
not
choice_selected
and
choice
.
value
in
tip
.
require_with_defaults
)
or
if
((
not
choice_selected
and
choice
.
value
.
get
()
in
tip
.
require_with_defaults
)
or
(
choice_selected
and
choice
.
value
in
tip
.
reject_with_defaults
)):
(
choice_selected
and
choice
.
value
.
get
()
in
tip
.
reject_with_defaults
)):
choice_completed
=
False
choice_completed
=
False
completed
=
completed
and
choice_completed
completed
=
completed
and
choice_completed
...
@@ -86,8 +90,6 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -86,8 +90,6 @@ class MRQBlock(QuestionnaireAbstractBlock):
self
.
message
=
u'Your answer is correct!'
if
completed
else
u'Your answer is incorrect.'
self
.
message
=
u'Your answer is correct!'
if
completed
else
u'Your answer is incorrect.'
# What's the proper way to get my value saved? it doesn't work without '.value'
# this is incorrect and the num_attempts is resetted if we restart the server.
num_attempts
=
self
.
num_attempts
.
get
()
+
1
if
self
.
max_attempts
else
0
num_attempts
=
self
.
num_attempts
.
get
()
+
1
if
self
.
max_attempts
else
0
setattr
(
self
,
'num_attempts'
,
num_attempts
)
setattr
(
self
,
'num_attempts'
,
num_attempts
)
...
@@ -99,9 +101,9 @@ class MRQBlock(QuestionnaireAbstractBlock):
...
@@ -99,9 +101,9 @@ class MRQBlock(QuestionnaireAbstractBlock):
if
max_attempts_reached
and
(
not
completed
or
num_attempts
>
max_attempts
):
if
max_attempts_reached
and
(
not
completed
or
num_attempts
>
max_attempts
):
completed
=
True
completed
=
True
self
.
message
+=
u' You have reached the maximum number of attempts for this question. '
\
self
.
message
=
self
.
message
.
get
()
+
u' You have reached the maximum number of attempts for this question. '
\
'Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.'
u
'Your next answers won''t be saved. You can check the answer(s) using the "Show Answer(s)" button.'
else
:
# only save the student_choices if there was a attempt left, might be incorrect or unuseful
self
.
student_choices
=
submissions
self
.
student_choices
=
submissions
result
=
{
result
=
{
...
...
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