Commit 2ad515d1 by Don Mitchell

Move singleton accessor w/ django dependencies to same place as modulestore() singleton accessor

parent 2702d8a6
......@@ -8,6 +8,7 @@ from __future__ import absolute_import
from importlib import import_module
from django.conf import settings
from xmodule.modulestore.loc_mapper_store import LocMapperStore
_MODULESTORES = {}
......@@ -53,3 +54,18 @@ def modulestore(name='default'):
settings.MODULESTORE[name]['OPTIONS'])
return _MODULESTORES[name]
_loc_singleton = None
def loc_mapper():
"""
Get the loc mapper which bidirectionally maps Locations to Locators. Used like modulestore() as
a singleton accessor.
"""
# pylint: disable=W0603
global _loc_singleton
# pylint: disable=W0212
if _loc_singleton is None:
# instantiate
_loc_singleton = LocMapperStore(settings.modulestore_options)
return _loc_singleton
'''
Method for converting among our differing Location/Locator whatever reprs
'''
from __future__ import absolute_import
from random import randint
import re
import pymongo
from django.conf import settings
from xmodule.modulestore.exceptions import InvalidLocationError, ItemNotFoundError, DuplicateItemError
from xmodule.modulestore.locator import BlockUsageLocator
from xmodule.modulestore.mongo import draft
from xmodule.modulestore import Location
def loc_mapper():
"""
Get the loc mapper which bidirectionally maps Locations to Locators. Used like modulestore() as
a singleton accessor.
"""
# pylint: disable=W0212
if LocMapperStore._singleton is None:
# instantiate
LocMapperStore(settings.modulestore_options)
return LocMapperStore._singleton
class LocMapperStore(object):
'''
This store persists mappings among the addressing schemes. At this time, it's between the old i4x Location
......@@ -38,8 +25,6 @@ class LocMapperStore(object):
or dominant store, but that's not a requirement. This store creates its own connection.
'''
_singleton = None
def __init__(self, host, db, collection, port=27017, user=None, password=None, **kwargs):
'''
Constructor
......@@ -55,7 +40,6 @@ class LocMapperStore(object):
self.location_map = self.db[collection + '.location_map']
self.location_map.write_concern = {'w': 1}
LocMapperStore._singleton = self
# location_map functions
......
......@@ -8,7 +8,7 @@ import uuid
from xmodule.modulestore import Location
from xmodule.modulestore.locator import BlockUsageLocator
from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError
from xmodule.modulestore.LocMapperStore import LocMapperStore
from xmodule.modulestore.loc_mapper_store import LocMapperStore
class TestLocationMapper(unittest.TestCase):
......
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