Commit 0feba83d by noraiz-anwar

for testing purpose on sandbox

parent 0edcf26a
...@@ -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( # Give the user admin ("Instructor") role for this library:
*CourseStaffRole(source_course_id).users_with_role() 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
) )
...@@ -502,7 +502,11 @@ def course_listing(request): ...@@ -502,7 +502,11 @@ def course_listing(request):
org = request.GET.get('org', '') if optimization_enabled else None org = request.GET.get('org', '') if optimization_enabled else None
courses_iter, in_process_course_actions = get_courses_accessible_to_user(request, org) courses_iter, in_process_course_actions = get_courses_accessible_to_user(request, org)
user = request.user user = request.user
start_time = time.time()
libraries = _accessible_libraries_iter(request.user, org) if LIBRARIES_ENABLED else [] libraries = _accessible_libraries_iter(request.user, org) if LIBRARIES_ENABLED else []
log.info('_accessible_libraries_iter completed in [%f]', (time.time() - start_time))
def format_in_process_course_view(uca): def format_in_process_course_view(uca):
""" """
......
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