Acknowledge the fact that right now keystore is really just a module store. If we need a keystore that returns other objects, we can reexctract the base class into it's own module again
This commit is contained in:
@@ -3,15 +3,15 @@
|
||||
###
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
from keystore.django import keystore
|
||||
from keystore.xml import XMLModuleStore
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.xml import XMLModuleStore
|
||||
|
||||
unnamed_modules = 0
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = \
|
||||
'''Import the specified data directory into the default keystore'''
|
||||
'''Import the specified data directory into the default ModuleStore'''
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if len(args) != 3:
|
||||
@@ -21,9 +21,9 @@ class Command(BaseCommand):
|
||||
|
||||
module_store = XMLModuleStore(org, course, data_dir, 'xmodule.raw_module.RawDescriptor', eager=True)
|
||||
for module in module_store.modules.itervalues():
|
||||
keystore().create_item(module.location)
|
||||
modulestore().create_item(module.location)
|
||||
if 'data' in module.definition:
|
||||
keystore().update_item(module.location, module.definition['data'])
|
||||
modulestore().update_item(module.location, module.definition['data'])
|
||||
if 'children' in module.definition:
|
||||
keystore().update_children(module.location, module.definition['children'])
|
||||
keystore().update_metadata(module.location, dict(module.metadata))
|
||||
modulestore().update_children(module.location, module.definition['children'])
|
||||
modulestore().update_metadata(module.location, dict(module.metadata))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from mitxmako.shortcuts import render_to_response
|
||||
from keystore.django import keystore
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from django_future.csrf import ensure_csrf_cookie
|
||||
from django.http import HttpResponse
|
||||
import json
|
||||
@@ -12,14 +12,14 @@ def index(request):
|
||||
org = 'mit.edu'
|
||||
course = '6002xs12'
|
||||
name = '6.002_Spring_2012'
|
||||
course = keystore().get_item(['i4x', org, course, 'course', name])
|
||||
course = modulestore().get_item(['i4x', org, course, 'course', name])
|
||||
weeks = course.get_children()
|
||||
return render_to_response('index.html', {'weeks': weeks})
|
||||
|
||||
|
||||
def edit_item(request):
|
||||
item_id = request.GET['id']
|
||||
item = keystore().get_item(item_id)
|
||||
item = modulestore().get_item(item_id)
|
||||
return render_to_response('unit.html', {
|
||||
'contents': item.get_html(),
|
||||
'js_module': item.js_module_name(),
|
||||
@@ -31,7 +31,7 @@ def edit_item(request):
|
||||
def save_item(request):
|
||||
item_id = request.POST['id']
|
||||
data = json.loads(request.POST['data'])
|
||||
keystore().update_item(item_id, data)
|
||||
modulestore().update_item(item_id, data)
|
||||
return HttpResponse(json.dumps({}))
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ def temp_force_export(request):
|
||||
org = 'mit.edu'
|
||||
course = '6002xs12'
|
||||
name = '6.002_Spring_2012'
|
||||
course = keystore().get_item(['i4x', org, course, 'course', name])
|
||||
course = modulestore().get_item(['i4x', org, course, 'course', name])
|
||||
fs = OSFS('../data-export-test')
|
||||
xml = course.export_to_xml(fs)
|
||||
with fs.open('course.xml', 'w') as course_xml:
|
||||
|
||||
@@ -6,9 +6,9 @@ from .common import *
|
||||
DEBUG = True
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
KEYSTORE = {
|
||||
MODULESTORE = {
|
||||
'default': {
|
||||
'ENGINE': 'keystore.mongo.MongoModuleStore',
|
||||
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
|
||||
'OPTIONS': {
|
||||
'default_class': 'xmodule.raw_module.RawDescriptor',
|
||||
'host': 'localhost',
|
||||
|
||||
@@ -17,7 +17,7 @@ for app in os.listdir(PROJECT_ROOT / 'djangoapps'):
|
||||
NOSE_ARGS += ['--cover-package', app]
|
||||
TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
|
||||
|
||||
KEYSTORE = {
|
||||
MODULESTORE = {
|
||||
'host': 'localhost',
|
||||
'db': 'mongo_base',
|
||||
'collection': 'key_store',
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
"""
|
||||
Module that provides a connection to the keystore specified in the django settings.
|
||||
|
||||
Passes settings.KEYSTORE as kwargs to MongoModuleStore
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
_KEYSTORES = {}
|
||||
|
||||
|
||||
def keystore(name='default'):
|
||||
global _KEYSTORES
|
||||
|
||||
if name not in _KEYSTORES:
|
||||
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]
|
||||
@@ -145,8 +145,8 @@ class ModuleStore(object):
|
||||
recent revision
|
||||
|
||||
If any segment of the location is None except revision, raises
|
||||
keystore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
|
||||
xmodule.modulestore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises xmodule.modulestore.exceptions.ItemNotFoundError
|
||||
|
||||
location: Something that can be passed to Location
|
||||
default_class: An XModuleDescriptor subclass to use if no plugin matching the
|
||||
26
common/lib/xmodule/modulestore/django.py
Normal file
26
common/lib/xmodule/modulestore/django.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""
|
||||
Module that provides a connection to the ModuleStore specified in the django settings.
|
||||
|
||||
Passes settings.MODULESTORE as kwargs to MongoModuleStore
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from importlib import import_module
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
_MODULESTORES = {}
|
||||
|
||||
|
||||
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)
|
||||
_MODULESTORES[name] = class_(
|
||||
**settings.MODULESTORE[name]['OPTIONS'])
|
||||
|
||||
return _MODULESTORES[name]
|
||||
@@ -31,8 +31,8 @@ class MongoModuleStore(ModuleStore):
|
||||
recent revision
|
||||
|
||||
If any segment of the location is None except revision, raises
|
||||
keystore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
|
||||
xmodule.modulestore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises xmodule.modulestore.exceptions.ItemNotFoundError
|
||||
|
||||
location: Something that can be passed to Location
|
||||
"""
|
||||
@@ -1,6 +1,6 @@
|
||||
from nose.tools import assert_equals, assert_raises, assert_not_equals
|
||||
from keystore import Location
|
||||
from keystore.exceptions import InvalidLocationError
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.exceptions import InvalidLocationError
|
||||
|
||||
|
||||
def check_string_roundtrip(url):
|
||||
@@ -81,8 +81,8 @@ class XMLModuleStore(ModuleStore):
|
||||
recent revision
|
||||
|
||||
If any segment of the location is None except revision, raises
|
||||
keystore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises keystore.exceptions.ItemNotFoundError
|
||||
xmodule.modulestore.exceptions.InsufficientSpecificationError
|
||||
If no object is found at that location, raises xmodule.modulestore.exceptions.ItemNotFoundError
|
||||
|
||||
location: Something that can be passed to Location
|
||||
"""
|
||||
@@ -2,7 +2,7 @@ from lxml import etree
|
||||
import pkg_resources
|
||||
import logging
|
||||
|
||||
from keystore import Location
|
||||
from xmodule.modulestore import Location
|
||||
from functools import partial
|
||||
|
||||
log = logging.getLogger('mitx.' + __name__)
|
||||
@@ -231,7 +231,7 @@ class XModuleDescriptor(Plugin):
|
||||
definition: A dict containing `data` and `children` representing the problem definition
|
||||
|
||||
Current arguments passed in kwargs:
|
||||
location: A keystore.Location object indicating the name and ownership of this problem
|
||||
location: A xmodule.modulestore.Location object indicating the name and ownership of this problem
|
||||
shared_state_key: The key to use for sharing StudentModules with other
|
||||
modules of this type
|
||||
metadata: A dictionary containing the following optional keys:
|
||||
|
||||
@@ -10,7 +10,7 @@ import xmodule
|
||||
|
||||
import mitxmako.middleware as middleware
|
||||
middleware.MakoMiddleware()
|
||||
from keystore.django import keystore
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from courseware.models import StudentModuleCache
|
||||
from courseware.module_render import get_module
|
||||
|
||||
@@ -78,7 +78,7 @@ class Command(BaseCommand):
|
||||
|
||||
# TODO (cpennington): Get coursename in a legitimate way
|
||||
course_location = 'i4x://edx/6002xs12/course/6.002_Spring_2012'
|
||||
student_module_cache = StudentModuleCache(sample_user, keystore().get_item(course_location))
|
||||
student_module_cache = StudentModuleCache(sample_user, modulestore().get_item(course_location))
|
||||
(course, _, _, _) = get_module(sample_user, None, course_location, student_module_cache)
|
||||
|
||||
to_run = [
|
||||
|
||||
@@ -6,7 +6,7 @@ from django.http import Http404
|
||||
from django.http import HttpResponse
|
||||
from lxml import etree
|
||||
|
||||
from keystore.django import keystore
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from mitxmako.shortcuts import render_to_string
|
||||
from models import StudentModule, StudentModuleCache
|
||||
|
||||
@@ -129,7 +129,7 @@ def toc_for_course(user, request, course_location, active_chapter, active_sectio
|
||||
chapters with name 'hidden' are skipped.
|
||||
'''
|
||||
|
||||
student_module_cache = StudentModuleCache(user, keystore().get_item(course_location), depth=2)
|
||||
student_module_cache = StudentModuleCache(user, modulestore().get_item(course_location), depth=2)
|
||||
(course, _, _, _) = get_module(user, request, course_location, student_module_cache)
|
||||
|
||||
chapters = list()
|
||||
@@ -161,7 +161,7 @@ def get_section(course, chapter, section):
|
||||
section: Section name
|
||||
"""
|
||||
try:
|
||||
course_module = keystore().get_item(course)
|
||||
course_module = modulestore().get_item(course)
|
||||
except:
|
||||
log.exception("Unable to load course_module")
|
||||
return None
|
||||
@@ -205,7 +205,7 @@ def get_module(user, request, location, student_module_cache, position=None):
|
||||
instance_module is a StudentModule specific to this module for this student
|
||||
shared_module is a StudentModule specific to all modules with the same 'shared_state_key' attribute, or None if the module doesn't elect to share state
|
||||
'''
|
||||
descriptor = keystore().get_item(location)
|
||||
descriptor = modulestore().get_item(location)
|
||||
|
||||
instance_module = student_module_cache.lookup(descriptor.category, descriptor.location.url())
|
||||
shared_state_key = getattr(descriptor, 'shared_state_key', None)
|
||||
@@ -304,7 +304,7 @@ def modx_dispatch(request, dispatch=None, id=None):
|
||||
# If there are arguments, get rid of them
|
||||
dispatch, _, _ = dispatch.partition('?')
|
||||
|
||||
student_module_cache = StudentModuleCache(request.user, keystore().get_item(id))
|
||||
student_module_cache = StudentModuleCache(request.user, modulestore().get_item(id))
|
||||
instance, instance_module, shared_module, module_type = get_module(request.user, request, id, student_module_cache)
|
||||
|
||||
if instance_module is None:
|
||||
|
||||
@@ -16,7 +16,7 @@ from module_render import toc_for_course, get_module, get_section
|
||||
from models import StudentModuleCache
|
||||
from student.models import UserProfile
|
||||
from multicourse import multicourse_settings
|
||||
from keystore.django import keystore
|
||||
from xmodule.modulestore.django import modulestore
|
||||
|
||||
from util.cache import cache
|
||||
from student.models import UserTestGroup
|
||||
@@ -63,7 +63,7 @@ def gradebook(request):
|
||||
course_location = multicourse_settings.get_course_location(coursename)
|
||||
|
||||
for student in student_objects:
|
||||
student_module_cache = StudentModuleCache(student, keystore().get_item(course_location))
|
||||
student_module_cache = StudentModuleCache(student, modulestore().get_item(course_location))
|
||||
course, _, _, _ = get_module(request.user, request, course_location, student_module_cache)
|
||||
student_info.append({
|
||||
'username': student.username,
|
||||
@@ -93,7 +93,7 @@ def profile(request, student_id=None):
|
||||
|
||||
coursename = multicourse_settings.get_coursename_from_request(request)
|
||||
course_location = multicourse_settings.get_course_location(coursename)
|
||||
student_module_cache = StudentModuleCache(request.user, keystore().get_item(course_location))
|
||||
student_module_cache = StudentModuleCache(request.user, modulestore().get_item(course_location))
|
||||
course, _, _, _ = get_module(request.user, request, course_location, student_module_cache)
|
||||
|
||||
context = {'name': user_info.name,
|
||||
|
||||
@@ -138,9 +138,9 @@ COURSE_SETTINGS = {'6.002_Spring_2012': {'number' : '6.002x',
|
||||
|
||||
|
||||
############################### XModule Store ##################################
|
||||
KEYSTORE = {
|
||||
MODULESTORE = {
|
||||
'default': {
|
||||
'ENGINE': 'keystore.xml.XMLModuleStore',
|
||||
'ENGINE': 'xmodule.modulestore.xml.XMLModuleStore',
|
||||
'OPTIONS': {
|
||||
'org': 'edx',
|
||||
'course': '6002xs12',
|
||||
|
||||
Reference in New Issue
Block a user