Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
2ad515d1
Commit
2ad515d1
authored
Aug 12, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move singleton accessor w/ django dependencies to same place as modulestore() singleton accessor
parent
2702d8a6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
17 deletions
+17
-17
common/lib/xmodule/xmodule/modulestore/django.py
+16
-0
common/lib/xmodule/xmodule/modulestore/loc_mapper_store.py
+0
-16
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
+1
-1
No files found.
common/lib/xmodule/xmodule/modulestore/django.py
View file @
2ad515d1
...
...
@@ -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
common/lib/xmodule/xmodule/modulestore/
LocMapperS
tore.py
→
common/lib/xmodule/xmodule/modulestore/
loc_mapper_s
tore.py
View file @
2ad515d1
'''
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
...
...
common/lib/xmodule/xmodule/modulestore/tests/test_location_mapper.py
View file @
2ad515d1
...
...
@@ -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.
LocMapperS
tore
import
LocMapperStore
from
xmodule.modulestore.
loc_mapper_s
tore
import
LocMapperStore
class
TestLocationMapper
(
unittest
.
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment