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

This commit is contained in:
Calen Pennington
2012-06-27 14:17:15 -04:00
parent d02abac820
commit 3c054306c6
3 changed files with 21 additions and 13 deletions

View File

@@ -6,9 +6,9 @@ Passes settings.KEYSTORE as kwargs to MongoModuleStore
from __future__ import absolute_import
from importlib import import_module
from django.conf import settings
from .mongo import MongoModuleStore
from raw_module import RawDescriptor
_KEYSTORES = {}
@@ -17,9 +17,10 @@ def keystore(name='default'):
global _KEYSTORES
if name not in _KEYSTORES:
# TODO (cpennington): Load the default class from a string
_KEYSTORES[name] = MongoModuleStore(
default_class=RawDescriptor,
**settings.KEYSTORE[name])
class_path = settings.KEYSTORE[name]['ENGINE']
module_path, _, class_name = class_path.rpartition('.')
class_ = getattr(import_module(module_path), class_name)
_KEYSTORES[name] = class_(
**settings.KEYSTORE[name]['OPTIONS'])
return _KEYSTORES[name]

View File

@@ -1,7 +1,9 @@
import pymongo
from importlib import import_module
from xmodule.x_module import XModuleDescriptor, DescriptorSystem
from . import ModuleStore, Location
from .exceptions import ItemNotFoundError, InsufficientSpecificationError
from xmodule.x_module import XModuleDescriptor, DescriptorSystem
class MongoModuleStore(ModuleStore):
@@ -16,7 +18,10 @@ class MongoModuleStore(ModuleStore):
# Force mongo to report errors, at the expense of performance
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):
"""
@@ -29,8 +34,6 @@ class MongoModuleStore(ModuleStore):
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
location: Something that can be passed to Location
default_class: An XModuleDescriptor subclass to use if no plugin matching the
location is found
"""
query = {}