Commit d521a21a by Calen Pennington

Basic implementation of rendering templates from xmodule resources

parent 98607e2a
......@@ -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
......
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
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):
......
......@@ -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):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment