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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
8 deletions
+17
-8
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
+9
-7
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
):
pass
class
NotFoundError
(
Exception
):
pass
common/lib/xmodule/xmodule/modulestore/exceptions.py
View file @
0223f3ff
...
...
@@ -14,5 +14,10 @@ class InsufficientSpecificationError(Exception):
class
InvalidLocationError
(
Exception
):
pass
class
NoPathToItem
(
Exception
):
pass
class
DuplicateItemError
(
Exception
):
pass
common/lib/xmodule/xmodule/modulestore/mongo.py
View file @
0223f3ff
import
pymongo
from
bson.objectid
import
ObjectId
from
bson.son
import
SON
from
fs.osfs
import
OSFS
from
itertools
import
repeat
...
...
@@ -14,14 +13,13 @@ from mitxmako.shortcuts import render_to_string
from
.
import
ModuleStore
,
Location
from
.exceptions
import
(
ItemNotFoundError
,
InsufficientSpecificationError
,
NoPathToItem
)
NoPathToItem
,
DuplicateItemError
)
# 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,
# that assumption will have to change
class
CachingDescriptorSystem
(
MakoDescriptorSystem
):
"""
A system that has a cache of module json that it will use to load modules
...
...
@@ -215,15 +213,22 @@ class MongoModuleStore(ModuleStore):
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
):
"""
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
"""
try
:
self
.
collection
.
insert
({
'_id'
:
Location
(
location
)
.
dict
(),
})
except
pymongo
.
errors
.
DuplicateKeyError
:
raise
DuplicateItemError
(
location
)
def
update_item
(
self
,
location
,
data
):
"""
...
...
@@ -286,8 +291,6 @@ class MongoModuleStore(ModuleStore):
{
'_id'
:
True
})
return
[
i
[
'_id'
]
for
i
in
items
]
def
path_to_location
(
self
,
location
,
course_name
=
None
):
'''
Try to find a course_id/chapter/section[/position] path to this location.
...
...
@@ -361,7 +364,6 @@ class MongoModuleStore(ModuleStore):
if
path
is
None
:
raise
(
NoPathToItem
(
location
))
n
=
len
(
path
)
course_id
=
CourseDescriptor
.
location_to_id
(
path
[
0
])
chapter
=
path
[
1
]
.
name
if
n
>
1
else
None
...
...
common/lib/xmodule/xmodule/modulestore/xml_importer.py
View file @
0223f3ff
import
logging
from
.xml
import
XMLModuleStore
from
.exceptions
import
DuplicateItemError
log
=
logging
.
getLogger
(
__name__
)
...
...
@@ -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
try
:
store
.
create_item
(
module
.
location
)
except
:
except
DuplicateItemError
:
log
.
exception
(
'Item already exists at
%
s'
%
module
.
location
.
url
())
pass
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