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
e6e914ec
Commit
e6e914ec
authored
Oct 09, 2014
by
dragonfi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use xblockutils in utils.py
parent
152ba723
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
57 deletions
+15
-57
mentoring/utils.py
+15
-57
No files found.
mentoring/utils.py
View file @
e6e914ec
...
@@ -21,8 +21,6 @@
...
@@ -21,8 +21,6 @@
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
# "AGPLv3". If not, see <http://www.gnu.org/licenses/>.
#
#
# Imports ###########################################################
import
logging
import
logging
import
os
import
os
import
pkg_resources
import
pkg_resources
...
@@ -32,39 +30,33 @@ from cStringIO import StringIO
...
@@ -32,39 +30,33 @@ from cStringIO import StringIO
from
django.template
import
Context
,
Template
from
django.template
import
Context
,
Template
from
xblock.fragment
import
Fragment
from
xblock.fragment
import
Fragment
from
xblockutils.resources
import
ResourceLoader
# Globals ###########################################################
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
# Functions #########################################################
loader
=
ResourceLoader
(
__name__
)
def
load_resource
(
resource_path
):
def
load_resource
(
resource_path
):
"""
return
loader
.
load_unicode
(
resource_path
)
Gets the content of a resource
"""
resource_content
=
pkg_resources
.
resource_string
(
__name__
,
resource_path
)
return
unicode
(
resource_content
)
def
render_template
(
template_path
,
context
=
{}):
def
render_template
(
template_path
,
context
=
{}):
"""
return
loader
.
render_template
(
template_path
,
context
)
Evaluate a template by resource path, applying the provided context
"""
template_str
=
load_resource
(
template_path
)
template
=
Template
(
template_str
)
return
template
.
render
(
Context
(
context
))
def
render_js_template
(
template_path
,
context
=
{},
id
=
'light-child-template'
):
def
render_js_template
(
template_path
,
context
=
{},
unique_id
=
'light-child-template'
):
"""
return
loader
.
render_js_template
(
template_path
,
unique_id
,
context
)
Render a js template.
"""
return
u"<script type='text/template' id='{}'>
\n
{}
\n
</script>"
.
format
(
def
get_scenarios_from_path
(
scenarios_path
,
include_identifier
=
False
):
id
,
return
loader
.
load_scenarios_from_path
(
scenarios_path
,
include_identifier
)
render_template
(
template_path
,
context
)
)
def
load_scenarios_from_path
(
scenarios_path
):
return
loader
.
load_scenarios_from_path
(
scenarios_path
,
include_identifier
=
True
)
def
list2csv
(
row
):
def
list2csv
(
row
):
...
@@ -78,40 +70,6 @@ def list2csv(row):
...
@@ -78,40 +70,6 @@ def list2csv(row):
return
f
.
read
()
return
f
.
read
()
def
get_scenarios_from_path
(
scenarios_path
,
include_identifier
=
False
):
"""
Returns an array of (title, xmlcontent) from files contained in a specified directory,
formatted as expected for the return value of the workbench_scenarios() method
"""
base_fullpath
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
scenarios_fullpath
=
os
.
path
.
join
(
base_fullpath
,
scenarios_path
)
scenarios
=
[]
if
os
.
path
.
isdir
(
scenarios_fullpath
):
for
template
in
os
.
listdir
(
scenarios_fullpath
):
if
not
template
.
endswith
(
'.xml'
):
continue
identifier
=
template
[:
-
4
]
title
=
identifier
.
replace
(
'_'
,
' '
)
.
title
()
template_path
=
os
.
path
.
join
(
scenarios_path
,
template
)
scenario
=
unicode
(
render_template
(
template_path
,
{
"url_name"
:
identifier
}))
if
not
include_identifier
:
scenarios
.
append
((
title
,
scenario
))
else
:
scenarios
.
append
((
identifier
,
title
,
scenario
))
return
scenarios
def
load_scenarios_from_path
(
scenarios_path
):
"""
Load all xml files contained in a specified directory, as workbench scenarios
"""
return
get_scenarios_from_path
(
scenarios_path
,
include_identifier
=
True
)
# Classes ###########################################################
class
XBlockWithChildrenFragmentsMixin
(
object
):
class
XBlockWithChildrenFragmentsMixin
(
object
):
def
get_children_fragment
(
self
,
context
,
view_name
=
'student_view'
,
instance_of
=
None
,
def
get_children_fragment
(
self
,
context
,
view_name
=
'student_view'
,
instance_of
=
None
,
not_instance_of
=
None
):
not_instance_of
=
None
):
...
...
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