diff --git a/cms/djangoapps/contentstore/tasks.py b/cms/djangoapps/contentstore/tasks.py index f18031af4b..f715d4e36b 100644 --- a/cms/djangoapps/contentstore/tasks.py +++ b/cms/djangoapps/contentstore/tasks.py @@ -38,7 +38,7 @@ from user_tasks.tasks import UserTask from contentstore.courseware_index import CoursewareSearchIndexer, LibrarySearchIndexer, SearchIndexingError from contentstore.storage import course_import_export_storage -from contentstore.utils import initialize_permissions, reverse_usage_url, execute_and_log_time +from contentstore.utils import initialize_permissions, reverse_usage_url from contentstore.video_utils import scrape_youtube_thumbnail from course_action_state.models import CourseRerunState from models.settings.course_metadata import CourseMetadata @@ -458,18 +458,16 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i # as the Mongo modulestore doesn't support multiple runs of the same course. store = modulestore() with store.default_store('split'): - execute_and_log_time( - store.clone_course, source_course_key, destination_course_key, user_id, fields=fields - ) + store.clone_course(source_course_key, destination_course_key, user_id, fields=fields) # set initial permissions for the user to access the course. - execute_and_log_time(initialize_permissions, destination_course_key, User.objects.get(id=user_id)) + initialize_permissions(destination_course_key, User.objects.get(id=user_id)) # update state: Succeeded CourseRerunState.objects.succeeded(course_key=destination_course_key) # call edxval to attach videos to the rerun - execute_and_log_time(copy_course_videos, source_course_key, destination_course_key) + copy_course_videos(source_course_key, destination_course_key) # Copy OrganizationCourse organization_course = OrganizationCourse.objects.filter(course_id=source_course_key_string).first() @@ -477,7 +475,14 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i if organization_course: clone_instance(organization_course, {'course_id': destination_course_key_string}) - execute_and_log_time(add_course_restrictions, source_course_key, destination_course_key) + # Copy RestrictedCourse + restricted_course = RestrictedCourse.objects.filter(course_key=source_course_key).first() + + if restricted_course: + country_access_rules = CountryAccessRule.objects.filter(restricted_course=restricted_course) + new_restricted_course = clone_instance(restricted_course, {'course_key': destination_course_key}) + for country_access_rule in country_access_rules: + clone_instance(country_access_rule, {'restricted_course': new_restricted_course}) return "succeeded" @@ -503,17 +508,6 @@ def rerun_course(source_course_key_string, destination_course_key_string, user_i return u"exception: " + text_type(exc) -def add_course_restrictions(source_course_key, destination_course_key): - """Adds course restrictions""" - restricted_course = RestrictedCourse.objects.filter(course_key=source_course_key).first() - - if restricted_course: - country_access_rules = CountryAccessRule.objects.filter(restricted_course=restricted_course) - new_restricted_course = clone_instance(restricted_course, {'course_key': destination_course_key}) - for country_access_rule in country_access_rules: - clone_instance(country_access_rule, {'restricted_course': new_restricted_course}) - - def deserialize_fields(json_fields): fields = json.loads(json_fields) for field_name, value in iteritems(fields): diff --git a/cms/djangoapps/contentstore/utils.py b/cms/djangoapps/contentstore/utils.py index 9a8db4941f..6cea7f65d1 100644 --- a/cms/djangoapps/contentstore/utils.py +++ b/cms/djangoapps/contentstore/utils.py @@ -4,7 +4,6 @@ Common utility functions useful throughout the contentstore from __future__ import print_function import logging -import time from datetime import datetime from django.conf import settings @@ -518,18 +517,3 @@ def is_self_paced(course): Returns True if course is self-paced, False otherwise. """ return course and course.self_paced - - -def execute_and_log_time(func, *args, **kwargs): - """ - Call func passed in method with logging the time it took to complete. - Temporarily added for EDUCATOR-4013, we will remove this once we get the required information. - """ - course_key = args[1] - start_time = time.time() - output = func(*args, **kwargs) - if 'MITx+7.00x' in unicode(course_key): - log.info( - u'Execution time for [%s] [%s] completed in [%f]', - func.__name__, course_key, (time.time() - start_time)) - return output