Commit 0feba83d by noraiz-anwar

for testing purpose on sandbox

parent 0edcf26a
......@@ -9,40 +9,50 @@ from opaque_keys.edx.keys import CourseKey
from student.roles import CourseInstructorRole, CourseStaffRole
from xmodule.modulestore import ModuleStoreEnum
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
#
class Command(BaseCommand):
"""
Clone a MongoDB-backed course to another location
Create 600 libraries
"""
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):
"""
Execute the command
"""
source_course_id = CourseKey.from_string(options['source_course_id'])
dest_course_id = CourseKey.from_string(options['dest_course_id'])
dirpath = u'library'
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):
if mstore.clone_course(source_course_id, dest_course_id, ModuleStoreEnum.UserID.mgmt_command):
print("copying User permissions...")
# purposely avoids auth.add_user b/c it doesn't have a caller to authorize
CourseInstructorRole(dest_course_id).add_users(
*CourseInstructorRole(source_course_id).users_with_role()
)
CourseStaffRole(dest_course_id).add_users(
*CourseStaffRole(source_course_id).users_with_role()
for i in range(1,600):
with store.default_store(ModuleStoreEnum.Type.split):
new_lib = store.create_library(
org='Arbisoft',
library='library{}'.format(i),
user_id=user.id,
fields={"display_name": 'New Library'},
)
# 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
)
......@@ -502,7 +502,11 @@ def course_listing(request):
org = request.GET.get('org', '') if optimization_enabled else None
courses_iter, in_process_course_actions = get_courses_accessible_to_user(request, org)
user = request.user
start_time = time.time()
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):
"""
......
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