Deleting a course from Open edX

Most of you might be wondering how to delete a course from the Open edX once its created!

Recently we at Blend-ed also had this issue. We couldn’t find any buttons that helped us do this either from the Studio or the LMS.

While going through some of the documentations we had in the Overhang.io discussions, I came across a tutor command. But when tested, it didn’t work well but later realised that it was due to the new tutor commands

Thus we found out this command (olive and above):

tutor <local or k8s based on your deployment> exec cms ./manage.py cms --setting=tutor.production delete_course <course_id>

For versions before Olive

tutor <local or k8s> run cms ./manage.py cms --setting=tutor.production delete_course <course_id>

6 Likes

One tip extra: if you can delete courses shown in the Studio app, you can help with the following command:

tutor <dev, local or k8s> exec cms ./manage.py cms --setting=tutor. Development delete_course 'COURSE_ID_TO_DELETE'

Where:

  • COURSE_ID_TO_DELETE, is the course to delete, you can find the course ID in the URL of the course. The course ID is the part of the URL that comes after course-v1:.
    If the URL of your course is https://your-domain/courses/course-v1:ORGANIZATION+COURSE_NUMBER+COURSE_RUN/, then the course ID is ORGANIZATION+COURSE_NUMBER+COURSE_RUN.
    For example, from the example URL https://your-domain/courses/course-v1:edX+DemoX+Demo_Course/ the course ID is 'course-v1:edX+DemoX+Demo_Course'

Then execute the following command:

tutor <dev, local or k8s> exec cms ./manage.py cms --setting=tutor.development delete_course 'course-v1:edX+DemoX+Demo_Course'

Response to answers:

Are you sure you want to delete course course-v1:edX+DemoX+Demo_Course? [y/N] y
Are you sure? This action cannot be undone! [y/N] y

When finish the course deletion, show the following message:

Deleted course course-v1:edX+DemoX+Demo_Course

This tip is very helpful when you need to delete some courses that you don’t need any more from the Studio app. For more details about some examples to use this command, check the following link https://github.com/openedx/edx-platform/blob/115833c323e5f0e32e9456aafcb43353cb6d97e5/cms/djangoapps/contentstore/management/commands/delete_course.py#L22

2 Likes

is there any way to delete course from admin panel , like it is not good running a command in server to delete a course ? , i mean from Ui (there is no option for delete course) side i did’t find anything .

Nope, there is no such option in admin panel!

Nope, there is no such option in admin panel!
you used this command tutor local run cms ./manage.py cms delete_course <your_course_id>

i check this management Command tutor dev run cms ./manage.py cms delete_course <course_key>
, 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 ??

@chintan and @sarina , do you have any thoughts on this .