Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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
edx
edx-platform
Commits
169d4b12
Commit
169d4b12
authored
Nov 30, 2012
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updates
parent
54c222a0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
11 deletions
+53
-11
common/lib/xmodule/xmodule/gst_module.py
+41
-9
lms/templates/graphical_slider_tool.html
+12
-2
No files found.
common/lib/xmodule/xmodule/gst_module.py
View file @
169d4b12
...
@@ -3,21 +3,19 @@ Graphical slider tool module is ungraded xmodule used by students to
...
@@ -3,21 +3,19 @@ Graphical slider tool module is ungraded xmodule used by students to
understand functional dependencies.
understand functional dependencies.
"""
"""
#
import json
import
json
import
logging
import
logging
from
lxml
import
etree
from
lxml
import
etree
import
xmltodict
import
re
from
xmodule.mako_module
import
MakoModuleDescriptor
from
xmodule.mako_module
import
MakoModuleDescriptor
from
xmodule.xml_module
import
XmlDescriptor
from
xmodule.xml_module
import
XmlDescriptor
from
xmodule.x_module
import
XModule
from
xmodule.x_module
import
XModule
from
xmodule.progress
import
Progress
from
xmodule.exceptions
import
NotFoundError
from
pkg_resources
import
resource_string
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.stringify
import
stringify_children
from
xmodule.stringify
import
stringify_children
# log = logging.getLogger("mitx.common.lib.seq_module")
log
=
logging
.
getLogger
(
"mitx.common.lib.gst_module"
)
class
GraphicalSliderToolModule
(
XModule
):
class
GraphicalSliderToolModule
(
XModule
):
...
@@ -71,15 +69,49 @@ class GraphicalSliderToolModule(XModule):
...
@@ -71,15 +69,49 @@ class GraphicalSliderToolModule(XModule):
instance_state
,
shared_state
,
**
kwargs
)
instance_state
,
shared_state
,
**
kwargs
)
def
get_html
(
self
):
def
get_html
(
self
):
self
.
get_configuration
()
gst_html
=
self
.
substitute_controls
(
self
.
definition
[
'render'
]
.
strip
())
params
=
{
params
=
{
'
main_html'
:
self
.
definition
[
'render'
]
.
strip
()
,
'
gst_html'
:
gst_html
,
'element_id'
:
self
.
location
.
html_id
(),
'element_id'
:
self
.
location
.
html_id
(),
'element_class'
:
self
.
location
.
category
'element_class'
:
self
.
location
.
category
,
'configuration_json'
:
self
.
configuration_json
}
}
self
.
content
=
(
self
.
system
.
render_template
(
self
.
content
=
(
self
.
system
.
render_template
(
'graphical_slider_tool.html'
,
params
))
'graphical_slider_tool.html'
,
params
))
# import ipdb; ipdb.set_trace()
return
self
.
content
return
self
.
content
def
substitute_controls
(
self
,
html_string
):
""" Substitue control element via their divs.
Simple variant: slider and plot controls are not inside any tag.
"""
plot_div
=
'<div class="${element_class}_plot" id="${element_id}_plot"
\
style="width: 600px; height: 600px; padding: 0px; position: relative;">
\
This is plot</div>'
html_string
.
replace
(
'$plot$'
,
plot_div
)
vars
=
[
x
[
'@var'
]
for
x
in
json
.
loads
(
self
.
configuration_json
)[
'root'
][
'sliders'
][
'slider'
]]
for
var
in
vars
:
m
=
re
.
match
(
'$slider
\
[([0-9]+),([0-9]+)]'
,
self
.
value
.
strip
()
.
replace
(
' '
,
''
))
if
m
:
# Note: we subtract 15 to compensate for the size of the dot on the screen.
# (is a 30x30 image--lms/static/green-pointer.png).
(
self
.
gx
,
self
.
gy
)
=
[
int
(
x
)
-
15
for
x
in
m
.
groups
()]
html
.
replace
(
'$slider'
+
' '
+
x
[
'@var'
])
return
html_string
def
get_configuration
(
self
):
"""Parse self.definition['configuration'] and transfer it to javascript
via json.
"""
# root added for interface compatibility with xmltodict.parse
self
.
configuration_json
=
json
.
dumps
(
xmltodict
.
parse
(
'<root>'
+
stringify_children
(
self
.
definition
[
'configuration'
])
+
'</root>'
))
return
self
.
configuration_json
class
GraphicalSliderToolDescriptor
(
MakoModuleDescriptor
,
XmlDescriptor
):
class
GraphicalSliderToolDescriptor
(
MakoModuleDescriptor
,
XmlDescriptor
):
module_class
=
GraphicalSliderToolModule
module_class
=
GraphicalSliderToolModule
...
...
lms/templates/graphical_slider_tool.html
View file @
169d4b12
<div
align=
"center"
id=
"element_id"
class=
"element_class"
>
<div
align=
"center"
id=
"${element_id}"
class=
"${element_class}"
>
${main_html}
<!-- xidden field to read configuration json from -->
<div
class=
"${element_class}"
id=
"${element_id}_json"
style=
"hidden"
data-json=
"${configuration_json}"
>
<!-- main xml with marked places for sliders, number and plots -->
${gst_html}
{# widgests
<div
class=
"slider"
id=
"${element_class}_1"
data-var=
"a"
></div>
#}
</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