diff --git a/cms/envs/dev.py b/cms/envs/dev.py index c5e1cf5689..13436ac5a5 100644 --- a/cms/envs/dev.py +++ b/cms/envs/dev.py @@ -24,6 +24,7 @@ MODULESTORE = { 'db': 'xmodule', 'collection': 'modulestore', 'fs_root': GITHUB_REPO_ROOT, + 'render_template': 'mitxmako.shortcuts.render_to_string', } } } diff --git a/cms/envs/test.py b/cms/envs/test.py index 3823cd9dd9..7dcd32caab 100644 --- a/cms/envs/test.py +++ b/cms/envs/test.py @@ -47,6 +47,7 @@ MODULESTORE = { 'db': 'test_xmodule', 'collection': 'modulestore', 'fs_root': GITHUB_REPO_ROOT, + 'render_template': 'mitxmako.shortcuts.render_to_string', } } } diff --git a/common/lib/mitxmako/README b/common/djangoapps/mitxmako/README similarity index 100% rename from common/lib/mitxmako/README rename to common/djangoapps/mitxmako/README diff --git a/common/lib/mitxmako/mitxmako/__init__.py b/common/djangoapps/mitxmako/__init__.py similarity index 100% rename from common/lib/mitxmako/mitxmako/__init__.py rename to common/djangoapps/mitxmako/__init__.py diff --git a/common/lib/mitxmako/mitxmako/makoloader.py b/common/djangoapps/mitxmako/makoloader.py similarity index 100% rename from common/lib/mitxmako/mitxmako/makoloader.py rename to common/djangoapps/mitxmako/makoloader.py diff --git a/common/lib/mitxmako/mitxmako/middleware.py b/common/djangoapps/mitxmako/middleware.py similarity index 100% rename from common/lib/mitxmako/mitxmako/middleware.py rename to common/djangoapps/mitxmako/middleware.py diff --git a/common/lib/mitxmako/mitxmako/shortcuts.py b/common/djangoapps/mitxmako/shortcuts.py similarity index 100% rename from common/lib/mitxmako/mitxmako/shortcuts.py rename to common/djangoapps/mitxmako/shortcuts.py diff --git a/common/lib/mitxmako/mitxmako/template.py b/common/djangoapps/mitxmako/template.py similarity index 100% rename from common/lib/mitxmako/mitxmako/template.py rename to common/djangoapps/mitxmako/template.py diff --git a/common/lib/mitxmako/mitxmako/templatetag_helpers.py b/common/djangoapps/mitxmako/templatetag_helpers.py similarity index 100% rename from common/lib/mitxmako/mitxmako/templatetag_helpers.py rename to common/djangoapps/mitxmako/templatetag_helpers.py diff --git a/common/lib/mitxmako/setup.py b/common/lib/mitxmako/setup.py deleted file mode 100644 index 535d86f90e..0000000000 --- a/common/lib/mitxmako/setup.py +++ /dev/null @@ -1,8 +0,0 @@ -from setuptools import setup, find_packages - -setup( - name="mitxmako", - version="0.1", - packages=find_packages(exclude=["tests"]), - install_requires=['distribute'], -) diff --git a/common/lib/xmodule/setup.py b/common/lib/xmodule/setup.py index 8a0a6bb139..cc5dfd183a 100644 --- a/common/lib/xmodule/setup.py +++ b/common/lib/xmodule/setup.py @@ -10,7 +10,6 @@ setup( }, requires=[ 'capa', - 'mitxmako' ], # See http://guide.python-distribute.org/creation.html#entry-points diff --git a/common/lib/xmodule/xmodule/modulestore/django.py b/common/lib/xmodule/xmodule/modulestore/django.py index 546aaf30c8..6a7315a074 100644 --- a/common/lib/xmodule/xmodule/modulestore/django.py +++ b/common/lib/xmodule/xmodule/modulestore/django.py @@ -12,15 +12,34 @@ from django.conf import settings _MODULESTORES = {} +FUNCTION_KEYS = ['render_template'] + + +def load_function(path): + """ + Load a function by name. + + path is a string of the form "path.to.module.function" + returns the imported python object `function` from `path.to.module` + """ + module_path, _, name = path.rpartition('.') + return getattr(import_module(module_path), name) + def modulestore(name='default'): global _MODULESTORES if name not in _MODULESTORES: - class_path = settings.MODULESTORE[name]['ENGINE'] - module_path, _, class_name = class_path.rpartition('.') - class_ = getattr(import_module(module_path), class_name) + class_ = load_function(settings.MODULESTORE[name]['ENGINE']) + + options = {} + options.update(settings.MODULESTORE[name]['OPTIONS']) + for key in FUNCTION_KEYS: + if key in options: + options[key] = load_function(options[key]) + _MODULESTORES[name] = class_( - **settings.MODULESTORE[name]['OPTIONS']) + **options + ) return _MODULESTORES[name] diff --git a/common/lib/xmodule/xmodule/modulestore/mongo.py b/common/lib/xmodule/xmodule/modulestore/mongo.py index b6101a6929..caada39f3e 100644 --- a/common/lib/xmodule/xmodule/modulestore/mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/mongo.py @@ -9,7 +9,6 @@ from importlib import import_module from xmodule.errortracker import null_error_tracker from xmodule.x_module import XModuleDescriptor from xmodule.mako_module import MakoDescriptorSystem -from mitxmako.shortcuts import render_to_string from . import ModuleStoreBase, Location from .exceptions import (ItemNotFoundError, @@ -82,7 +81,8 @@ class MongoModuleStore(ModuleStoreBase): """ # TODO (cpennington): Enable non-filesystem filestores - def __init__(self, host, db, collection, fs_root, port=27017, default_class=None, + def __init__(self, host, db, collection, fs_root, render_template, + port=27017, default_class=None, error_tracker=null_error_tracker): ModuleStoreBase.__init__(self) @@ -108,6 +108,7 @@ class MongoModuleStore(ModuleStoreBase): self.default_class = None self.fs_root = path(fs_root) self.error_tracker = error_tracker + self.render_template = render_template def _clean_item_data(self, item): """ @@ -160,7 +161,7 @@ class MongoModuleStore(ModuleStoreBase): self.default_class, resource_fs, self.error_tracker, - render_to_string, + self.render_template, ) return system.load_item(item['location']) diff --git a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py index cb94444b7a..746240e763 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/test_mongo.py @@ -26,6 +26,7 @@ DB = 'test' COLLECTION = 'modulestore' FS_ROOT = DATA_DIR # TODO (vshnayder): will need a real fs_root for testing load_item DEFAULT_CLASS = 'xmodule.raw_module.RawDescriptor' +RENDER_TEMPLATE = lambda t_n, d, ctx=None, nsp='main': '' class TestMongoModuleStore(object): @@ -48,7 +49,7 @@ class TestMongoModuleStore(object): @staticmethod def initdb(): # connect to the db - store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, default_class=DEFAULT_CLASS) + store = MongoModuleStore(HOST, DB, COLLECTION, FS_ROOT, RENDER_TEMPLATE, default_class=DEFAULT_CLASS) # Explicitly list the courses to load (don't want the big one) courses = ['toy', 'simple'] import_from_xml(store, DATA_DIR, courses) diff --git a/lms/djangoapps/courseware/tests/tests.py b/lms/djangoapps/courseware/tests/tests.py index f3b978adac..9682040b36 100644 --- a/lms/djangoapps/courseware/tests/tests.py +++ b/lms/djangoapps/courseware/tests/tests.py @@ -56,6 +56,7 @@ def mongo_store_config(data_dir): 'db': 'xmodule', 'collection': 'modulestore', 'fs_root': data_dir, + 'render_template': 'mitxmako.shortcuts.render_to_string', } } } diff --git a/lms/envs/dev_mongo.py b/lms/envs/dev_mongo.py index 1c4980a538..6af0a429bb 100644 --- a/lms/envs/dev_mongo.py +++ b/lms/envs/dev_mongo.py @@ -14,6 +14,7 @@ MODULESTORE = { 'db': 'xmodule', 'collection': 'modulestore', 'fs_root': GITHUB_REPO_ROOT, + 'render_template': 'mitxmako.shortcuts.render_to_string', } } } diff --git a/repo-requirements.txt b/repo-requirements.txt index 74bf02b5bd..dced5b960b 100644 --- a/repo-requirements.txt +++ b/repo-requirements.txt @@ -1,3 +1,2 @@ -e common/lib/capa --e common/lib/mitxmako -e common/lib/xmodule