Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
edx-platform-release
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hsin-Yu Chien
edx-platform-release
Commits
e431378f
Commit
e431378f
authored
12 years ago
by
Victor Shnayder
Browse files
Options
Downloads
Patches
Plain Diff
Add first pass at a randomize module
parent
ada9ff7f
No related branches found
Branches containing commit
Tags
release-2020-12-18-07.19
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
common/lib/xmodule/setup.py
+1
-0
1 addition, 0 deletions
common/lib/xmodule/setup.py
common/lib/xmodule/xmodule/randomize_module.py
+122
-0
122 additions, 0 deletions
common/lib/xmodule/xmodule/randomize_module.py
with
123 additions
and
0 deletions
common/lib/xmodule/setup.py
+
1
−
0
View file @
e431378f
...
...
@@ -28,6 +28,7 @@ setup(
"
error = xmodule.error_module:ErrorDescriptor
"
,
"
problem = xmodule.capa_module:CapaDescriptor
"
,
"
problemset = xmodule.seq_module:SequenceDescriptor
"
,
"
randomize = xmodule.randomize_module:RandomizeDescriptor
"
,
"
section = xmodule.backcompat_module:SemanticSectionDescriptor
"
,
"
sequential = xmodule.seq_module:SequenceDescriptor
"
,
"
slides = xmodule.backcompat_module:TranslateCustomTagDescriptor
"
,
...
...
This diff is collapsed.
Click to expand it.
common/lib/xmodule/xmodule/randomize_module.py
0 → 100644
+
122
−
0
View file @
e431378f
import
json
import
logging
import
random
from
xmodule.mako_module
import
MakoModuleDescriptor
from
xmodule.x_module
import
XModule
from
xmodule.xml_module
import
XmlDescriptor
from
xmodule.modulestore
import
Location
from
xmodule.seq_module
import
SequenceDescriptor
from
pkg_resources
import
resource_string
log
=
logging
.
getLogger
(
'
mitx.
'
+
__name__
)
class
RandomizeModule
(
XModule
):
"""
Chooses a random child module. Chooses the same one every time for each student.
Example:
<randomize>
<problem url_name=
"
problem1
"
/>
<problem url_name=
"
problem2
"
/>
<problem url_name=
"
problem3
"
/>
</randomize>
User notes:
- If you
'
re randomizing amongst graded modules, each of them MUST be worth the same
number of points. Otherwise, the earth will be overrun by monsters from the
deeps. You have been warned.
Technical notes:
- There is more dark magic in this code than I
'
d like. The whole varying-children +
grading interaction is a tangle between super and subclasses of descriptors and
modules.
"""
def
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
=
None
,
shared_state
=
None
,
**
kwargs
):
XModule
.
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
,
shared_state
,
**
kwargs
)
# NOTE: calling self.get_children() creates a circular reference--
# it calls get_child_descriptors() internally, but that doesn't work until
# we've picked a choice
num_choices
=
len
(
self
.
descriptor
.
get_children
())
self
.
choice
=
None
if
instance_state
is
not
None
:
state
=
json
.
loads
(
instance_state
)
self
.
choice
=
state
.
get
(
'
choice
'
,
None
)
if
self
.
choice
>
num_choices
:
# Oops. Children changed. Reset.
self
.
choice
=
None
if
self
.
choice
is
None
:
# choose one based on the system seed, or randomly if that's not available
if
num_choices
>
0
:
if
system
.
seed
is
not
None
:
self
.
choice
=
system
.
seed
%
num_choices
else
:
self
.
choice
=
random
.
randrange
(
0
,
num_choices
)
log
.
debug
(
"
********* self.choice = %s
"
,
self
.
choice
)
if
self
.
choice
is
not
None
:
self
.
child_descriptor
=
self
.
descriptor
.
get_children
()[
self
.
choice
]
# Now get_children() should return a list with one element
log
.
debug
(
"
children of randomize module (should be only 1): %s
"
,
self
.
get_children
())
self
.
child
=
self
.
get_children
()[
0
]
else
:
self
.
child_descriptor
=
None
self
.
child
=
None
def
get_instance_state
(
self
):
return
json
.
dumps
({
'
choice
'
:
self
.
choice
})
def
get_child_descriptors
(
self
):
"""
For grading--return just the chosen child.
"""
if
self
.
child_descriptor
is
None
:
return
[]
return
[
self
.
child_descriptor
]
def
get_html
(
self
):
if
self
.
child
is
None
:
# raise error instead? In fact, could complain on descriptor load...
return
"
<div>Nothing to randomize between</div>
"
return
self
.
child
.
get_html
()
def
get_icon_class
(
self
):
return
self
.
child
.
get_icon_class
()
if
self
.
child
else
'
other
'
class
RandomizeDescriptor
(
SequenceDescriptor
):
# the editing interface can be the same as for sequences -- just a container
module_class
=
RandomizeModule
filename_extension
=
"
xml
"
stores_state
=
True
def
definition_to_xml
(
self
,
resource_fs
):
xml_object
=
etree
.
Element
(
'
randomize
'
)
for
child
in
self
.
get_children
():
xml_object
.
append
(
etree
.
fromstring
(
child
.
export_to_xml
(
resource_fs
)))
return
xml_object
def
has_dynamic_children
(
self
):
"""
Grading needs to know that only one of the children is actually
"
real
"
. This
makes it use module.get_child_descriptors().
"""
return
True
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment