Commit 3b4fb616 by Calen Pennington

Push dependency on mitxmako up out of mako_module

parent d7178e4a
from x_module import XModuleDescriptor from x_module import XModuleDescriptor, DescriptorSystem
from mitxmako.shortcuts import render_to_string
class MakoDescriptorSystem(DescriptorSystem):
def __init__(self, render_template, *args, **kwargs):
self.render_template = render_template
super(MakoDescriptorSystem, self).__init__(*args, **kwargs)
class MakoModuleDescriptor(XModuleDescriptor): class MakoModuleDescriptor(XModuleDescriptor):
...@@ -12,6 +17,11 @@ class MakoModuleDescriptor(XModuleDescriptor): ...@@ -12,6 +17,11 @@ class MakoModuleDescriptor(XModuleDescriptor):
the descriptor as the `module` parameter to that template the descriptor as the `module` parameter to that template
""" """
def __init__(self, system, definition=None, **kwargs):
if getattr(system, 'render_template', None) is None:
raise TypeError('{system} must have a render_template function in order to use a MakoDescriptor'.format(system=system))
super(MakoModuleDescriptor, self).__init__(system, definition, **kwargs)
def get_context(self): def get_context(self):
""" """
Return the context to render the mako template with Return the context to render the mako template with
...@@ -19,4 +29,4 @@ class MakoModuleDescriptor(XModuleDescriptor): ...@@ -19,4 +29,4 @@ class MakoModuleDescriptor(XModuleDescriptor):
return {'module': self} return {'module': self}
def get_html(self): def get_html(self):
return render_to_string(self.mako_template, self.get_context()) return self.system.render_template(self.mako_template, self.get_context())
import pymongo import pymongo
from importlib import import_module from importlib import import_module
from xmodule.x_module import XModuleDescriptor, DescriptorSystem from xmodule.x_module import XModuleDescriptor
from xmodule.mako_module import MakoDescriptorSystem
from mitxmako.shortcuts import render_to_string
from . import ModuleStore, Location from . import ModuleStore, Location
from .exceptions import ItemNotFoundError, InsufficientSpecificationError from .exceptions import ItemNotFoundError, InsufficientSpecificationError
...@@ -54,7 +56,7 @@ class MongoModuleStore(ModuleStore): ...@@ -54,7 +56,7 @@ class MongoModuleStore(ModuleStore):
# TODO (cpennington): Pass a proper resources_fs to the system # TODO (cpennington): Pass a proper resources_fs to the system
return XModuleDescriptor.load_from_json( return XModuleDescriptor.load_from_json(
item, DescriptorSystem(self.get_item, None), self.default_class) item, MakoDescriptorSystem(load_item=self.get_item, resources_fs=None, render_template=render_to_string), self.default_class)
def create_item(self, location): def create_item(self, location):
""" """
......
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