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
f731a1cb
Commit
f731a1cb
authored
Nov 09, 2017
by
noraiz-anwar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
management command overidden fro test on sandbox
parent
5260473c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
20 deletions
+31
-20
cms/djangoapps/contentstore/management/commands/clone_course.py
+31
-20
No files found.
cms/djangoapps/contentstore/management/commands/clone_course.py
View file @
f731a1cb
...
@@ -9,40 +9,50 @@ from opaque_keys.edx.keys import CourseKey
...
@@ -9,40 +9,50 @@ from opaque_keys.edx.keys import CourseKey
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
from
student.roles
import
CourseInstructorRole
,
CourseStaffRole
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore
import
ModuleStoreEnum
from
xmodule.modulestore.django
import
modulestore
from
xmodule.modulestore.django
import
modulestore
from
django.contrib.auth.models
import
User
from
xmodule.modulestore.xml_importer
import
import_library_from_xml
from
xmodule.contentstore.django
import
contentstore
from
contentstore.utils
import
add_instructor
,
reverse_library_url
#
#
# To run from command line: ./manage.py cms clone_course --settings=dev master/300/cough edx/111/foo
# To run from command line: ./manage.py cms clone_course --settings=dev master/300/cough edx/111/foo
#
#
class
Command
(
BaseCommand
):
class
Command
(
BaseCommand
):
"""
"""
C
lone a MongoDB-backed course to another location
C
reate 600 libraries
"""
"""
help
=
'Clone a MongoDB backed course to another location'
help
=
'Clone a MongoDB backed course to another location'
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'source_course_id'
,
help
=
'Course ID to copy from'
)
parser
.
add_argument
(
'dest_course_id'
,
help
=
'Course ID to copy to'
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
"""
"""
Execute the command
Execute the command
"""
"""
source_course_id
=
CourseKey
.
from_string
(
options
[
'source_course_id'
])
dirpath
=
u'library'
dest_course_id
=
CourseKey
.
from_string
(
options
[
'dest_course_id'
])
LIBRARY_ROOT
=
'library.xml'
root_name
=
LIBRARY_ROOT
import_func
=
import_library_from_xml
mstore
=
modulestore
()
user
=
User
.
objects
.
get
(
username
=
'honor'
)
store
=
modulestore
()
print
(
"Cloning course {0} to {1}"
.
format
(
source_course_id
,
dest_course_id
))
with
mstore
.
bulk_operations
(
dest_course_id
):
for
i
in
range
(
1
,
600
):
if
mstore
.
clone_course
(
source_course_id
,
dest_course_id
,
ModuleStoreEnum
.
UserID
.
mgmt_command
):
with
store
.
default_store
(
ModuleStoreEnum
.
Type
.
split
):
print
(
"copying User permissions..."
)
new_lib
=
store
.
create_library
(
# purposely avoids auth.add_user b/c it doesn't have a caller to authorize
org
=
'Arbisoft'
,
CourseInstructorRole
(
dest_course_id
)
.
add_users
(
library
=
'library{}'
.
format
(
i
),
*
CourseInstructorRole
(
source_course_id
)
.
users_with_role
()
user_id
=
user
.
id
,
)
fields
=
{
"display_name"
:
'New Library'
},
CourseStaffRole
(
dest_course_id
)
.
add_users
(
*
CourseStaffRole
(
source_course_id
)
.
users_with_role
()
)
)
# Give the user admin ("Instructor") role for this library:
add_instructor
(
new_lib
.
location
.
library_key
,
user
,
user
)
courselike_module
=
modulestore
()
.
get_library
(
new_lib
.
location
.
library_key
)
courselike_items
=
import_func
(
modulestore
(),
user
.
id
,
u'/edx/app/edxapp/edx-platform'
,
[
dirpath
],
load_error_modules
=
False
,
static_content_store
=
contentstore
(),
target_id
=
new_lib
.
location
.
library_key
)
\ No newline at end of file
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