Commit d73599a2 by Calen Pennington

Get custom_tag templates using system.filestore so that they work in multicourse

parent e273c229
from xmodule.x_module import XModule from xmodule.x_module import XModule
from xmodule.raw_module import RawDescriptor from xmodule.raw_module import RawDescriptor
from lxml import etree from lxml import etree
from mako.template import Template
class CustomTagModule(XModule): class CustomTagModule(XModule):
...@@ -30,9 +31,10 @@ class CustomTagModule(XModule): ...@@ -30,9 +31,10 @@ class CustomTagModule(XModule):
def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs): def __init__(self, system, location, definition, instance_state=None, shared_state=None, **kwargs):
XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs) XModule.__init__(self, system, location, definition, instance_state, shared_state, **kwargs)
xmltree = etree.fromstring(self.definition['data']) xmltree = etree.fromstring(self.definition['data'])
filename = xmltree.find('impl').text template_name = xmltree.find('impl').text
params = dict(xmltree.items()) params = dict(xmltree.items())
self.html = self.system.render_template(filename, params, namespace='custom_tags') with self.system.filestore.open('custom_tags/{name}'.format(name=template_name)) as template:
self.html = Template(template.read()).render(**params)
def get_html(self): def get_html(self):
return self.html return self.html
......
...@@ -69,21 +69,15 @@ sys.path.append(COMMON_ROOT / 'lib') ...@@ -69,21 +69,15 @@ sys.path.append(COMMON_ROOT / 'lib')
# templates # templates
MAKO_MODULE_DIR = tempfile.mkdtemp('mako') MAKO_MODULE_DIR = tempfile.mkdtemp('mako')
MAKO_TEMPLATES = {} MAKO_TEMPLATES = {}
MAKO_TEMPLATES['course'] = [DATA_DIR]
MAKO_TEMPLATES['sections'] = [DATA_DIR / 'sections']
MAKO_TEMPLATES['custom_tags'] = [DATA_DIR / 'custom_tags']
MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates', MAKO_TEMPLATES['main'] = [PROJECT_ROOT / 'templates',
COMMON_ROOT / 'templates', COMMON_ROOT / 'templates',
COMMON_ROOT / 'lib' / 'capa' / 'templates', COMMON_ROOT / 'lib' / 'capa' / 'templates',
COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates', COMMON_ROOT / 'djangoapps' / 'pipeline_mako' / 'templates']
DATA_DIR / 'info',
DATA_DIR / 'problems']
# This is where Django Template lookup is defined. There are a few of these # This is where Django Template lookup is defined. There are a few of these
# still left lying around. # still left lying around.
TEMPLATE_DIRS = ( TEMPLATE_DIRS = (
PROJECT_ROOT / "templates", PROJECT_ROOT / "templates",
DATA_DIR / "problems",
) )
TEMPLATE_CONTEXT_PROCESSORS = ( TEMPLATE_CONTEXT_PROCESSORS = (
......
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