Commit 40337068 by Calen Pennington

Add the ability to specify Keystore engines and default descriptor classes by name from settings

parent a8eb7e57
...@@ -8,9 +8,13 @@ TEMPLATE_DEBUG = DEBUG ...@@ -8,9 +8,13 @@ TEMPLATE_DEBUG = DEBUG
KEYSTORE = { KEYSTORE = {
'default': { 'default': {
'host': 'localhost', 'ENGINE': 'keystore.mongo.MongoModuleStore',
'db': 'mongo_base', 'OPTIONS': {
'collection': 'key_store', 'default_class': 'xmodule.raw_module.RawDescriptor',
'host': 'localhost',
'db': 'mongo_base',
'collection': 'key_store',
}
} }
} }
......
...@@ -6,9 +6,9 @@ Passes settings.KEYSTORE as kwargs to MongoModuleStore ...@@ -6,9 +6,9 @@ Passes settings.KEYSTORE as kwargs to MongoModuleStore
from __future__ import absolute_import from __future__ import absolute_import
from importlib import import_module
from django.conf import settings from django.conf import settings
from .mongo import MongoModuleStore
from raw_module import RawDescriptor
_KEYSTORES = {} _KEYSTORES = {}
...@@ -17,9 +17,10 @@ def keystore(name='default'): ...@@ -17,9 +17,10 @@ def keystore(name='default'):
global _KEYSTORES global _KEYSTORES
if name not in _KEYSTORES: if name not in _KEYSTORES:
# TODO (cpennington): Load the default class from a string class_path = settings.KEYSTORE[name]['ENGINE']
_KEYSTORES[name] = MongoModuleStore( module_path, _, class_name = class_path.rpartition('.')
default_class=RawDescriptor, class_ = getattr(import_module(module_path), class_name)
**settings.KEYSTORE[name]) _KEYSTORES[name] = class_(
**settings.KEYSTORE[name]['OPTIONS'])
return _KEYSTORES[name] return _KEYSTORES[name]
import pymongo import pymongo
from importlib import import_module
from xmodule.x_module import XModuleDescriptor, DescriptorSystem
from . import ModuleStore, Location from . import ModuleStore, Location
from .exceptions import ItemNotFoundError, InsufficientSpecificationError from .exceptions import ItemNotFoundError, InsufficientSpecificationError
from xmodule.x_module import XModuleDescriptor, DescriptorSystem
class MongoModuleStore(ModuleStore): class MongoModuleStore(ModuleStore):
...@@ -16,7 +18,10 @@ class MongoModuleStore(ModuleStore): ...@@ -16,7 +18,10 @@ class MongoModuleStore(ModuleStore):
# Force mongo to report errors, at the expense of performance # Force mongo to report errors, at the expense of performance
self.collection.safe = True self.collection.safe = True
self.default_class = default_class
module_path, _, class_name = default_class.rpartition('.')
class_ = getattr(import_module(module_path), class_name)
self.default_class = class_
def get_item(self, location): def get_item(self, location):
""" """
...@@ -29,8 +34,6 @@ class MongoModuleStore(ModuleStore): ...@@ -29,8 +34,6 @@ class MongoModuleStore(ModuleStore):
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
location: Something that can be passed to Location location: Something that can be passed to Location
default_class: An XModuleDescriptor subclass to use if no plugin matching the
location is found
""" """
query = {} query = {}
......
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