hi,
i tried to mimic management Command tutor dev run cms ./manage.py cms delete_course <course_key>
for deleting course
, i go through this file Command File delete_course.py
and then i made changes in CourseContext
Model for custom delete method here Like:
def delete(self, *args, **kwargs):
# Delete related Sectors instances
try:
course_key = self.learning_context.context_key
module_store = modulestore()
with module_store.bulk_operations(course_key):
module_store.delete_course(course_key, ModuleStoreEnum.UserID.mgmt_command)
contentstore().delete_all_course_assets(course_key)
# staff_role = CourseStaffRole(course_key)
# staff_role.remove_users(*staff_role.users_with_role())
# instructor_role = CourseInstructorRole(course_key)
# instructor_role.remove_users(*instructor_role.users_with_role())
except:
pass
super().delete(*args, **kwargs)
but as you commented lines are for removing all instructor and staff users from the given course
as these are the functions used in delete_course.py
from cms/djangoapps/contentstore/utils.py
def remove_all_instructors(course_key):
"""
Removes all instructor and staff users from the given course.
"""
staff_role = CourseStaffRole(course_key)
staff_role.remove_users(*staff_role.users_with_role())
instructor_role = CourseInstructorRole(course_key)
instructor_role.remove_users(*instructor_role.users_with_role())
def delete_course(course_key, user_id, keep_instructors=False):
"""
Delete course from module store and if specified remove user and
groups permissions from course.
"""
_delete_course_from_modulestore(course_key, user_id)
if not keep_instructors:
_remove_instructors(course_key)
def _delete_course_from_modulestore(course_key, user_id):
"""
Delete course from MongoDB. Deleting course will fire a signal which will result into
deletion of the courseware associated with a course_key.
"""
module_store = modulestore()
with module_store.bulk_operations(course_key):
module_store.delete_course(course_key, user_id)
, what i have written working , but when i uncomment those four line gives me circular import error.
now i want to ask , how to Removes all instructor and staff users from the given course or if i do not remove this what impact does it have ??