add another command line argument to allow users to only simulate a delete (i.e. show what items would be deleted). This is a handy sanity checker.

This commit is contained in:
Chris Dodge
2013-02-25 16:00:35 -05:00
parent dde4fc981b
commit 816b0edfb0
3 changed files with 25 additions and 10 deletions

View File

@@ -21,18 +21,26 @@ class Command(BaseCommand):
'''Delete a MongoDB backed course'''
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("delete_course requires one argument: <location>")
if len(args) != 1 and len(args) != 2:
raise CommandError("delete_course requires one argument: <location> |commit|")
loc_str = args[0]
commit = False
if len(args) == 2:
commit = args[1] == 'commit'
if commit:
print 'Actually going to delete the course from DB....'
ms = modulestore('direct')
cs = contentstore()
if query_yes_no("Deleting course {0}. Confirm?".format(loc_str), default="no"):
if query_yes_no("Are you sure. This action cannot be undone!", default="no"):
loc = CourseDescriptor.id_to_location(loc_str)
if delete_course(ms, cs, loc) == True:
if delete_course(ms, cs, loc, commit) == True:
print 'removing User permissions from course....'
# in the django layer, we need to remove all the user permissions groups associated with this course
_delete_course_group(loc)
if commit:
_delete_course_group(loc)