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
d4b8a7bb
Commit
d4b8a7bb
authored
Dec 20, 2012
by
Alexander Kryklia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added export function
parent
9bf1a6e2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
35 deletions
+38
-35
common/lib/xmodule/xmodule/gst_module.py
+38
-35
No files found.
common/lib/xmodule/xmodule/gst_module.py
View file @
d4b8a7bb
...
@@ -25,6 +25,8 @@ class GraphicalSliderToolModule(XModule):
...
@@ -25,6 +25,8 @@ class GraphicalSliderToolModule(XModule):
js
=
{
js
=
{
'js'
:
[
'js'
:
[
# 3rd party libraries used by graphic slider tool.
# TODO - where to store them - outside xmodule?
resource_string
(
__name__
,
'js/src/graphical_slider_tool/jstat-1.0.0.min.js'
),
resource_string
(
__name__
,
'js/src/graphical_slider_tool/jstat-1.0.0.min.js'
),
resource_string
(
__name__
,
'js/src/graphical_slider_tool/gst_main.js'
),
resource_string
(
__name__
,
'js/src/graphical_slider_tool/gst_main.js'
),
...
@@ -44,32 +46,40 @@ class GraphicalSliderToolModule(XModule):
...
@@ -44,32 +46,40 @@ class GraphicalSliderToolModule(XModule):
def
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
=
None
,
def
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
=
None
,
shared_state
=
None
,
**
kwargs
):
shared_state
=
None
,
**
kwargs
):
"""
"""
For XML file format please look at documentation.
For XML file format please look at documentation.
TODO - receive
information where to store XML documentation.
"""
"""
XModule
.
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
XModule
.
__init__
(
self
,
system
,
location
,
definition
,
descriptor
,
instance_state
,
shared_state
,
**
kwargs
)
instance_state
,
shared_state
,
**
kwargs
)
def
get_html
(
self
):
def
get_html
(
self
):
self
.
get_configuration
()
""" Renders parameters to template. """
# these both will be used in class methods
self
.
html_id
=
self
.
location
.
html_id
()
self
.
html_id
=
self
.
location
.
html_id
()
self
.
html_class
=
self
.
location
.
category
self
.
html_class
=
self
.
location
.
category
gst_html
=
self
.
substitute_controls
(
self
.
definition
[
'render'
]
.
strip
())
# import ipdb; ipdb.set_trace()
params
=
{
params
=
{
'gst_html'
:
gst_html
,
'gst_html'
:
self
.
substitute_controls
(
self
.
definition
[
'render'
])
,
'element_id'
:
self
.
html_id
,
'element_id'
:
self
.
html_id
,
'element_class'
:
self
.
html_class
,
'element_class'
:
self
.
html_class
,
'configuration_json'
:
self
.
configuration_json
'configuration_json'
:
self
.
build_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
):
def
substitute_controls
(
self
,
html_string
):
""" Substitue control element via their divs.
""" Substitutes control elements via their divs.
Simple variant: slider and plot controls are not inside any tag.
TODO: change regexps to html parsing via beautiful soup or something
similar (aim : simpler support).
Args:
html_string: rendered html string with controls as xml tags
(<slider var="a"/>)
Returns:
html_string with control tags replaced by proper divs
(<slider var="a"/> -> <div class="....slider" > </div>)
"""
"""
#substitute plot
#substitute plot
plot_div
=
'<div class="{element_class}_plot" id="{element_id}_plot"
\
plot_div
=
'<div class="{element_class}_plot" id="{element_id}_plot"
\
...
@@ -98,8 +108,7 @@ class GraphicalSliderToolModule(XModule):
...
@@ -98,8 +108,7 @@ class GraphicalSliderToolModule(XModule):
variables
=
[
x
[
'@var'
]
for
x
in
variables
]
variables
=
[
x
[
'@var'
]
for
x
in
variables
]
else
:
else
:
return
html_string
return
html_string
# if variables[0] == 'v':
# import ipdb; ipdb.set_trace()
#substitute sliders
#substitute sliders
slider_div
=
'<div class="{element_class}_slider"
\
slider_div
=
'<div class="{element_class}_slider"
\
id="{element_id}_slider_{var}"
\
id="{element_id}_slider_{var}"
\
...
@@ -143,11 +152,9 @@ class GraphicalSliderToolModule(XModule):
...
@@ -143,11 +152,9 @@ class GraphicalSliderToolModule(XModule):
# different id
# different id
instances
=
re
.
findall
(
r'<textbox\s+(?=[^<>]*var\=[\"\']'
+
var
+
'[
\"\'
])'
\
instances
=
re
.
findall
(
r'<textbox\s+(?=[^<>]*var\=[\"\']'
+
var
+
'[
\"\'
])'
\
+
r'[^<>]*/>'
,
html_string
,
flags
=
re
.
UNICODE
|
re
.
DOTALL
)
+
r'[^<>]*/>'
,
html_string
,
flags
=
re
.
UNICODE
|
re
.
DOTALL
)
# import ipdb; ipdb.set_trace()
for
input_def
in
instances
:
# for multiple inputs per var
for
input_def
in
instances
:
# for multiple inputs per var
input_index
+=
1
input_index
+=
1
# extract var and readonly before style!
# extract var and readonly before style!
# import ipdb; ipdb.set_trace()
var_substring
=
re
.
search
(
r'(var\=[\"\']'
+
var
+
r'[\"\'])'
,
var_substring
=
re
.
search
(
r'(var\=[\"\']'
+
var
+
r'[\"\'])'
,
input_def
)
.
group
()
input_def
)
.
group
()
input_def
=
input_def
.
replace
(
var_substring
,
''
)
input_def
=
input_def
.
replace
(
var_substring
,
''
)
...
@@ -164,28 +171,28 @@ class GraphicalSliderToolModule(XModule):
...
@@ -164,28 +171,28 @@ class GraphicalSliderToolModule(XModule):
style
=
style
.
groups
()[
0
]
style
=
style
.
groups
()[
0
]
else
:
else
:
style
=
''
style
=
''
# import ipdb; ipdb.set_trace()
replacement
=
input_el
.
format
(
element_class
=
self
.
html_class
,
replacement
=
input_el
.
format
(
element_class
=
self
.
html_class
,
element_id
=
self
.
html_id
,
element_id
=
self
.
html_id
,
var
=
var
,
readonly
=
readonly
,
style
=
style
,
var
=
var
,
readonly
=
readonly
,
style
=
style
,
input_index
=
input_index
)
input_index
=
input_index
)
# import ipdb; ipdb.set_trace()
html_string
=
re
.
sub
(
r'<textbox\s+(?=[^<>]*var\=[\"\']('
+
\
html_string
=
re
.
sub
(
r'<textbox\s+(?=[^<>]*var\=[\"\']('
+
\
var
+
')[
\"\'
])'
+
r'[^<>]*/>'
,
var
+
')[
\"\'
])'
+
r'[^<>]*/>'
,
replacement
,
html_string
,
count
=
1
,
flags
=
re
.
UNICODE
|
re
.
DOTALL
)
replacement
,
html_string
,
count
=
1
,
flags
=
re
.
UNICODE
|
re
.
DOTALL
)
return
html_string
return
html_string
def
get_configuration
(
self
):
def
build_configuration_json
(
self
):
"""Parse self.definition['configuration'] and transfer it to javascript
"""Creates json element from xml element (with aim to transfer later
via json.
directly to javascript via hidden field in template). Steps:
1. Convert xml tree to python dict.
2. Dump dict to json.
"""
"""
# root added for interface compatibility with xmltodict.parse
# <root> added for interface compatibility with xmltodict.parse
# import ipdb; ipdb.set_trace()
# class added for javascript's part purposes
self
.
configuration_json
=
json
.
dumps
(
return
json
.
dumps
(
xmltodict
.
parse
(
'<root class="'
+
self
.
html_class
+
xmltodict
.
parse
(
'<root class="'
+
self
.
location
.
category
+
'">'
+
'">'
+
self
.
definition
[
'configuration'
]
+
'</root>'
))
stringify_children
(
self
.
definition
[
'configuration'
])
+
'</root>'
))
return
self
.
configuration_json
class
GraphicalSliderToolDescriptor
(
MakoModuleDescriptor
,
XmlDescriptor
):
class
GraphicalSliderToolDescriptor
(
MakoModuleDescriptor
,
XmlDescriptor
):
...
@@ -220,25 +227,21 @@ class GraphicalSliderToolDescriptor(MakoModuleDescriptor, XmlDescriptor):
...
@@ -220,25 +227,21 @@ class GraphicalSliderToolDescriptor(MakoModuleDescriptor, XmlDescriptor):
def
parse
(
k
):
def
parse
(
k
):
"""Assumes that xml_object has child k"""
"""Assumes that xml_object has child k"""
return
stringify_children
(
xml_object
.
xpath
(
k
)[
0
])
return
stringify_children
(
xml_object
.
xpath
(
k
)[
0
])
return
{
return
{
'render'
:
parse
(
'render'
),
'render'
:
parse
(
'render'
),
'configuration'
:
xml_object
.
xpath
(
'configuration'
)[
0
]
'configuration'
:
parse
(
'configuration'
)
}
}
def
definition_to_xml
(
self
,
resource_fs
):
def
definition_to_xml
(
self
,
resource_fs
):
'''Return an xml element representing this definition.
'''Return an xml element representing this definition.'''
Not implemented'''
xml_object
=
etree
.
Element
(
'graphical_slider_tool'
)
# import ipdb; ipdb.set_trace()
xml_object
=
etree
.
Element
(
'gst'
)
def
add_child
(
k
):
def
add_child
(
k
):
# child_str = '<{tag}>{body}</{tag}>'.format(tag=k, body=self.definition[k])
child_str
=
'<{tag}>{body}</{tag}>'
.
format
(
tag
=
k
,
body
=
self
.
definition
[
k
])
child_str
=
child
.
export_to_xml
(
resource_fs
)
child_node
=
etree
.
fromstring
(
child_str
)
child_node
=
etree
.
fromstring
(
child_str
)
xml_object
.
append
(
child_node
)
xml_object
.
append
(
child_node
)
for
child
in
self
.
get_children
()
:
for
child
in
[
'render'
,
'configuration'
]
:
add_child
(
child
)
add_child
(
child
)
return
xml_object
return
xml_object
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