Commit f731a1cb by noraiz-anwar

management command overidden fro test on sandbox

parent 5260473c
...@@ -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):
""" """
Clone a MongoDB-backed course to another location Create 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment