Commit 8d61f66c by Calen Pennington

Acknowledge the fact that right now keystore is really just a module store. If…

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