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
0223f3ff
Commit
0223f3ff
authored
Jul 27, 2012
by
Calen Pennington
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return a custom error for duplicate elements, and ignore it when loading into mongo
parent
f5cf87f8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
20 additions
and
11 deletions
+20
-11
cms/djangoapps/contentstore/__init__.py
+0
-0
common/lib/xmodule/xmodule/exceptions.py
+1
-0
common/lib/xmodule/xmodule/modulestore/exceptions.py
+5
-0
common/lib/xmodule/xmodule/modulestore/mongo.py
+12
-10
common/lib/xmodule/xmodule/modulestore/xml_importer.py
+2
-1
No files found.
cms/djangoapps/contentstore/__init__.py
deleted
100644 → 0
View file @
f5cf87f8
common/lib/xmodule/xmodule/exceptions.py
View file @
0223f3ff
class
InvalidDefinitionError
(
Exception
):
class
InvalidDefinitionError
(
Exception
):
pass
pass
class
NotFoundError
(
Exception
):
class
NotFoundError
(
Exception
):
pass
pass
common/lib/xmodule/xmodule/modulestore/exceptions.py
View file @
0223f3ff
...
@@ -14,5 +14,10 @@ class InsufficientSpecificationError(Exception):
...
@@ -14,5 +14,10 @@ class InsufficientSpecificationError(Exception):
class
InvalidLocationError
(
Exception
):
class
InvalidLocationError
(
Exception
):
pass
pass
class
NoPathToItem
(
Exception
):
class
NoPathToItem
(
Exception
):
pass
pass
class
DuplicateItemError
(
Exception
):
pass
common/lib/xmodule/xmodule/modulestore/mongo.py
View file @
0223f3ff
import
pymongo
import
pymongo
from
bson.objectid
import
ObjectId
from
bson.son
import
SON
from
bson.son
import
SON
from
fs.osfs
import
OSFS
from
fs.osfs
import
OSFS
from
itertools
import
repeat
from
itertools
import
repeat
...
@@ -14,14 +13,13 @@ from mitxmako.shortcuts import render_to_string
...
@@ -14,14 +13,13 @@ from mitxmako.shortcuts import render_to_string
from
.
import
ModuleStore
,
Location
from
.
import
ModuleStore
,
Location
from
.exceptions
import
(
ItemNotFoundError
,
InsufficientSpecificationError
,
from
.exceptions
import
(
ItemNotFoundError
,
InsufficientSpecificationError
,
NoPathToItem
)
NoPathToItem
,
DuplicateItemError
)
# TODO (cpennington): This code currently operates under the assumption that
# TODO (cpennington): This code currently operates under the assumption that
# there is only one revision for each item. Once we start versioning inside the CMS,
# there is only one revision for each item. Once we start versioning inside the CMS,
# that assumption will have to change
# that assumption will have to change
class
CachingDescriptorSystem
(
MakoDescriptorSystem
):
class
CachingDescriptorSystem
(
MakoDescriptorSystem
):
"""
"""
A system that has a cache of module json that it will use to load modules
A system that has a cache of module json that it will use to load modules
...
@@ -215,15 +213,22 @@ class MongoModuleStore(ModuleStore):
...
@@ -215,15 +213,22 @@ class MongoModuleStore(ModuleStore):
return
self
.
_load_items
(
list
(
items
),
depth
)
return
self
.
_load_items
(
list
(
items
),
depth
)
# TODO (cpennington): This needs to be replaced by clone_item as soon as we allow
# creation of items from the cms
def
create_item
(
self
,
location
):
def
create_item
(
self
,
location
):
"""
"""
Create an empty item at the specified location with the supplied editor
Create an empty item at the specified location.
If that location already exists, raises a DuplicateItemError
location: Something that can be passed to Location
location: Something that can be passed to Location
"""
"""
self
.
collection
.
insert
({
try
:
'_id'
:
Location
(
location
)
.
dict
(),
self
.
collection
.
insert
({
})
'_id'
:
Location
(
location
)
.
dict
(),
})
except
pymongo
.
errors
.
DuplicateKeyError
:
raise
DuplicateItemError
(
location
)
def
update_item
(
self
,
location
,
data
):
def
update_item
(
self
,
location
,
data
):
"""
"""
...
@@ -286,8 +291,6 @@ class MongoModuleStore(ModuleStore):
...
@@ -286,8 +291,6 @@ class MongoModuleStore(ModuleStore):
{
'_id'
:
True
})
{
'_id'
:
True
})
return
[
i
[
'_id'
]
for
i
in
items
]
return
[
i
[
'_id'
]
for
i
in
items
]
def
path_to_location
(
self
,
location
,
course_name
=
None
):
def
path_to_location
(
self
,
location
,
course_name
=
None
):
'''
'''
Try to find a course_id/chapter/section[/position] path to this location.
Try to find a course_id/chapter/section[/position] path to this location.
...
@@ -361,7 +364,6 @@ class MongoModuleStore(ModuleStore):
...
@@ -361,7 +364,6 @@ class MongoModuleStore(ModuleStore):
if
path
is
None
:
if
path
is
None
:
raise
(
NoPathToItem
(
location
))
raise
(
NoPathToItem
(
location
))
n
=
len
(
path
)
n
=
len
(
path
)
course_id
=
CourseDescriptor
.
location_to_id
(
path
[
0
])
course_id
=
CourseDescriptor
.
location_to_id
(
path
[
0
])
chapter
=
path
[
1
]
.
name
if
n
>
1
else
None
chapter
=
path
[
1
]
.
name
if
n
>
1
else
None
...
...
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
0223f3ff
import
logging
import
logging
from
.xml
import
XMLModuleStore
from
.xml
import
XMLModuleStore
from
.exceptions
import
DuplicateItemError
log
=
logging
.
getLogger
(
__name__
)
log
=
logging
.
getLogger
(
__name__
)
...
@@ -27,7 +28,7 @@ def import_from_xml(store, data_dir, course_dirs=None, eager=True,
...
@@ -27,7 +28,7 @@ def import_from_xml(store, data_dir, course_dirs=None, eager=True,
# This should in the future create new revisions of the items on import
# This should in the future create new revisions of the items on import
try
:
try
:
store
.
create_item
(
module
.
location
)
store
.
create_item
(
module
.
location
)
except
:
except
DuplicateItemError
:
log
.
exception
(
'Item already exists at
%
s'
%
module
.
location
.
url
())
log
.
exception
(
'Item already exists at
%
s'
%
module
.
location
.
url
())
pass
pass
if
'data'
in
module
.
definition
:
if
'data'
in
module
.
definition
:
...
...
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