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

This commit is contained in:
Don Mitchell
2013-08-12 13:27:22 -04:00
parent 2702d8a636
commit 2ad515d15a
3 changed files with 17 additions and 17 deletions

View File

@@ -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

View File

@@ -1,28 +1,15 @@
'''
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

View File

@@ -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):