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
84da71d9
Commit
84da71d9
authored
May 15, 2014
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure all cms commands accept either deprecated or new syntax for keys
LMS-2712
parent
77b895cb
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
20 deletions
+58
-20
cms/djangoapps/contentstore/management/commands/check_course.py
+6
-1
cms/djangoapps/contentstore/management/commands/clone_course.py
+13
-2
cms/djangoapps/contentstore/management/commands/delete_course.py
+8
-3
cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
+1
-1
cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py
+8
-1
cms/djangoapps/contentstore/management/commands/export.py
+9
-4
cms/djangoapps/contentstore/management/commands/export_all_courses.py
+0
-1
cms/djangoapps/contentstore/management/commands/migrate_to_split.py
+13
-7
No files found.
cms/djangoapps/contentstore/management/commands/check_course.py
View file @
84da71d9
...
...
@@ -2,6 +2,8 @@ from django.core.management.base import BaseCommand, CommandError
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.xml_importer
import
check_module_metadata_editability
from
xmodule.modulestore.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -11,7 +13,10 @@ class Command(BaseCommand):
if
len
(
args
)
!=
1
:
raise
CommandError
(
"check_course requires one argument: <course_id>"
)
course_key
=
CourseKey
.
from_string
(
args
[
0
])
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
store
=
modulestore
()
...
...
cms/djangoapps/contentstore/management/commands/clone_course.py
View file @
84da71d9
...
...
@@ -7,6 +7,8 @@ from xmodule.modulestore.django import modulestore
from
xmodule.contentstore.django
import
contentstore
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
from
xmodule.modulestore.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
#
...
...
@@ -16,13 +18,22 @@ class Command(BaseCommand):
"""Clone a MongoDB-backed course to another location"""
help
=
'Clone a MongoDB backed course to another location'
def
course_key_from_arg
(
self
,
arg
):
"""
Convert the command line arg into a course key
"""
try
:
return
CourseKey
.
from_string
(
arg
)
except
InvalidKeyError
:
return
SlashSeparatedCourseKey
.
from_deprecated_string
(
arg
)
def
handle
(
self
,
*
args
,
**
options
):
"Execute the command"
if
len
(
args
)
!=
2
:
raise
CommandError
(
"clone requires 2 arguments: <source-course_id> <dest-course_id>"
)
source_course_id
=
CourseKey
.
from_strin
g
(
args
[
0
])
dest_course_id
=
CourseKey
.
from_strin
g
(
args
[
1
])
source_course_id
=
self
.
course_key_from_ar
g
(
args
[
0
])
dest_course_id
=
self
.
course_key_from_ar
g
(
args
[
1
])
mstore
=
modulestore
(
'direct'
)
cstore
=
contentstore
()
...
...
cms/djangoapps/contentstore/management/commands/delete_course.py
View file @
84da71d9
...
...
@@ -5,6 +5,8 @@ from django.core.management.base import BaseCommand, CommandError
from
.prompt
import
query_yes_no
from
contentstore.utils
import
delete_course_and_groups
from
xmodule.modulestore.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -14,7 +16,10 @@ class Command(BaseCommand):
if
len
(
args
)
!=
1
and
len
(
args
)
!=
2
:
raise
CommandError
(
"delete_course requires one or more arguments: <course_id> |commit|"
)
course_id
=
CourseKey
.
from_string
(
args
[
0
])
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
commit
=
False
if
len
(
args
)
==
2
:
...
...
@@ -23,6 +28,6 @@ class Command(BaseCommand):
if
commit
:
print
(
'Actually going to delete the course from DB....'
)
if
query_yes_no
(
"Deleting course {0}. Confirm?"
.
format
(
course_
id
),
default
=
"no"
):
if
query_yes_no
(
"Deleting course {0}. Confirm?"
.
format
(
course_
key
),
default
=
"no"
):
if
query_yes_no
(
"Are you sure. This action cannot be undone!"
,
default
=
"no"
):
delete_course_and_groups
(
course_
id
,
commit
)
delete_course_and_groups
(
course_
key
,
commit
)
cms/djangoapps/contentstore/management/commands/edit_course_tabs.py
View file @
84da71d9
...
...
@@ -71,7 +71,7 @@ command again, adding --insert or --delete to edit the list.
course_key
=
CourseKey
.
from_string
(
options
[
'course'
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
options
[
'course'
])
print
u'Warning: you are using a deprecated format. Please use {} in the future'
.
format
(
course_key
)
course
=
get_course_by_id
(
course_key
)
print
'Warning: this command directly edits the list of course tabs in mongo.'
...
...
cms/djangoapps/contentstore/management/commands/empty_asset_trashcan.py
View file @
84da71d9
...
...
@@ -3,6 +3,8 @@ from xmodule.contentstore.utils import empty_asset_trashcan
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.keys
import
CourseKey
from
.prompt
import
query_yes_no
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -13,7 +15,12 @@ class Command(BaseCommand):
raise
CommandError
(
"empty_asset_trashcan requires one or no arguments: |<course_id>|"
)
if
len
(
args
)
==
1
:
course_ids
=
[
CourseKey
.
from_string
(
args
[
0
])]
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
course_ids
=
[
course_key
]
else
:
course_ids
=
[
course
.
id
for
course
in
modulestore
(
'direct'
)
.
get_courses
()]
...
...
cms/djangoapps/contentstore/management/commands/export.py
View file @
84da71d9
...
...
@@ -8,7 +8,8 @@ from xmodule.modulestore.xml_exporter import export_to_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.keys
import
CourseKey
from
xmodule.contentstore.django
import
contentstore
from
xmodule.course_module
import
CourseDescriptor
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
class
Command
(
BaseCommand
):
...
...
@@ -22,12 +23,16 @@ class Command(BaseCommand):
if
len
(
args
)
!=
2
:
raise
CommandError
(
"export requires two arguments: <course id> <output path>"
)
course_id
=
CourseKey
.
from_string
(
args
[
0
])
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
output_path
=
args
[
1
]
print
(
"Exporting course id = {0} to {1}"
.
format
(
course_
id
,
output_path
))
print
(
"Exporting course id = {0} to {1}"
.
format
(
course_
key
,
output_path
))
root_dir
=
os
.
path
.
dirname
(
output_path
)
course_dir
=
os
.
path
.
splitext
(
os
.
path
.
basename
(
output_path
))[
0
]
export_to_xml
(
modulestore
(
'direct'
),
contentstore
(),
course_
id
,
root_dir
,
course_dir
,
modulestore
())
export_to_xml
(
modulestore
(
'direct'
),
contentstore
(),
course_
key
,
root_dir
,
course_dir
,
modulestore
())
cms/djangoapps/contentstore/management/commands/export_all_courses.py
View file @
84da71d9
...
...
@@ -5,7 +5,6 @@ from django.core.management.base import BaseCommand, CommandError
from
xmodule.modulestore.xml_exporter
import
export_to_xml
from
xmodule.modulestore.django
import
modulestore
from
xmodule.contentstore.django
import
contentstore
from
xmodule.course_module
import
CourseDescriptor
class
Command
(
BaseCommand
):
...
...
cms/djangoapps/contentstore/management/commands/migrate_to_split.py
View file @
84da71d9
...
...
@@ -7,6 +7,9 @@ from django.contrib.auth.models import User
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.split_migrator
import
SplitMigrator
from
xmodule.modulestore.django
import
loc_mapper
from
xmodule.modulestore.keys
import
CourseKey
from
opaque_keys
import
InvalidKeyError
from
xmodule.modulestore.locations
import
SlashSeparatedCourseKey
def
user_from_str
(
identifier
):
...
...
@@ -28,20 +31,23 @@ class Command(BaseCommand):
"Migrate a course from old-Mongo to split-Mongo"
help
=
"Migrate a course from old-Mongo to split-Mongo"
args
=
"
location
email <new org> <new offering>"
args
=
"
course_key
email <new org> <new offering>"
def
parse_args
(
self
,
*
args
):
"""
Return a 4-tuple of (
location
, user, org, offering).
Return a 4-tuple of (
course_key
, user, org, offering).
If the user didn't specify an org & offering, those will be None.
"""
if
len
(
args
)
<
2
:
raise
CommandError
(
"migrate_to_split requires at least two arguments: "
"a
location
and a user identifier (email or ID)"
"a
course_key
and a user identifier (email or ID)"
)
location
=
args
[
0
]
try
:
course_key
=
CourseKey
.
from_string
(
args
[
0
])
except
InvalidKeyError
:
course_key
=
SlashSeparatedCourseKey
.
from_deprecated_string
(
args
[
0
])
try
:
user
=
user_from_str
(
args
[
1
])
...
...
@@ -54,10 +60,10 @@ class Command(BaseCommand):
except
IndexError
:
org
=
offering
=
None
return
location
,
user
,
org
,
offering
return
course_key
,
user
,
org
,
offering
def
handle
(
self
,
*
args
,
**
options
):
location
,
user
,
org
,
offering
=
self
.
parse_args
(
*
args
)
course_key
,
user
,
org
,
offering
=
self
.
parse_args
(
*
args
)
migrator
=
SplitMigrator
(
draft_modulestore
=
modulestore
(
'default'
),
...
...
@@ -66,4 +72,4 @@ class Command(BaseCommand):
loc_mapper
=
loc_mapper
(),
)
migrator
.
migrate_mongo_course
(
location
,
user
,
org
,
offering
)
migrator
.
migrate_mongo_course
(
course_key
,
user
,
org
,
offering
)
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