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
d521a21a
Commit
d521a21a
authored
Nov 15, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Basic implementation of rendering templates from xmodule resources
parent
98607e2a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
7 deletions
+30
-7
common/lib/xmodule/setup.py
+1
-0
common/lib/xmodule/xmodule/html_templates/vert_module.html
+0
-0
common/lib/xmodule/xmodule/module_resources.py
+10
-0
common/lib/xmodule/xmodule/vertical_module.py
+5
-6
common/lib/xmodule/xmodule/xmodule.py
+14
-1
No files found.
common/lib/xmodule/setup.py
View file @
d521a21a
...
...
@@ -12,6 +12,7 @@ setup(
'capa'
,
# TODO: This isn't actually forcing an install, for some reason
'fs (>= 0.4.0)'
,
'mako'
,
],
# See http://guide.python-distribute.org/creation.html#entry-points
...
...
lms/
templates/vert_module.html
→
common/lib/xmodule/xmodule/html_
templates/vert_module.html
View file @
d521a21a
File moved
common/lib/xmodule/xmodule/module_resources.py
0 → 100644
View file @
d521a21a
import
pkg_resources
from
mako.template
import
Template
def
render_template
(
template_name
,
context
):
return
Template
(
pkg_resources
.
resource_string
(
__name__
,
'html_templates/
%
s'
%
template_name
),
module_directory
=
'/tmp/xmodule_mako'
,
)
.
render
(
**
context
)
\ No newline at end of file
common/lib/xmodule/xmodule/vertical_module.py
View file @
d521a21a
from
.xmodule
import
XModule
from
.xmodule
import
XModule
,
register_view
from
.seq_module
import
SequenceDescriptor
from
.progress
import
Progress
from
.module_resources
import
render_template
# HACK: This shouldn't be hard-coded to two types
# OBSOLETE: This obsoletes 'type'
...
...
@@ -10,12 +11,10 @@ class_priority = ['video', 'problem']
class
VerticalModule
(
XModule
):
''' Layout module for laying out submodules vertically.'''
@register_view
(
'student_view'
)
def
get_html
(
self
):
if
self
.
contents
is
None
:
self
.
contents
=
[
child
.
get_html
()
for
child
in
self
.
get_display_items
()]
return
self
.
system
.
render_template
(
'vert_module.html'
,
{
'items'
:
self
.
contents
return
render_template
(
'vert_module.html'
,
{
'items'
:
[
child
.
render
()
for
child
in
self
.
children
]
})
def
get_progress
(
self
):
...
...
common/lib/xmodule/xmodule/xmodule.py
View file @
d521a21a
...
...
@@ -2,6 +2,7 @@ import logging
import
pkg_resources
import
yaml
import
os
import
inspect
from
functools
import
partial
from
lxml
import
etree
...
...
@@ -133,6 +134,12 @@ class HTMLSnippet(object):
.
format
(
self
.
__class__
))
def
register_view
(
view_name
):
def
wrapper
(
fn
):
setattr
(
fn
,
'view_name'
,
view_name
)
return
fn
return
wrapper
class
XModule
(
Plugin
,
HTMLSnippet
):
''' Implements a generic learning module.
...
...
@@ -180,7 +187,13 @@ class XModule(Plugin, HTMLSnippet):
self
.
student_state
=
student_state
def
render
(
self
,
view_name
):
return
"RENDER OF
%
s"
%
view_name
for
method_name
,
method_fn
in
inspect
.
getmembers
(
self
,
lambda
m
:
inspect
.
ismethod
(
m
)):
if
getattr
(
method_fn
,
'view_name'
,
None
)
is
not
None
:
return
method_fn
()
@property
def
children
(
self
):
return
self
.
runtime
.
children
@property
def
display_name
(
self
):
...
...
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