Commit 03b0bf22 by Justin Riley

add --dry-run option to reapply_extensions command

parent 571527f7
#!/usr/bin/python
from django.http import Http404
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand, CommandError, make_option
from courseware.courses import get_course_by_id
from instructor.views.tools import reapply_all_extensions
......@@ -9,12 +9,20 @@ from instructor.views.tools import reapply_all_extensions
class Command(BaseCommand):
args = "<course_id>"
help = "Reapply all extensions (fixes extensions for newly added problems)"
option_list = BaseCommand.option_list + (
make_option('--dry-run',
dest='dry_run',
action='store_true',
default=False,
help='Show what would be done without actually doing '
'anything'),
)
def handle(self, *args, **options):
if len(args) != 1:
raise CommandError("insufficient arguments")
try:
course = get_course_by_id(args[0])
reapply_all_extensions(course)
reapply_all_extensions(course, dry_run=options['dry_run'])
except (ValueError, Http404) as e:
raise CommandError(e)
......@@ -254,7 +254,12 @@ def dump_student_extensions(course, student):
"data": data}
def reapply_all_extensions(course):
def reapply_all_extensions(course, dry_run=False):
"""
Recursively reapply all extensions to each extended unit in course. This
fixes an issue where new xmodule children (ie new <problem> children) don't
inherit the same 'extended_due' as their parent.
"""
units = get_units_with_due_date(course)
units = dict([(u.location.url(), u) for u in units])
msks = units.keys()
......@@ -272,6 +277,10 @@ def reapply_all_extensions(course):
if not edue:
continue
unit = units.get(module.module_state_key)
if dry_run:
print('would reapply extension %s to %s for user %s' %
(edue, unit.location.url(), student.username))
else:
print('reapplying extension %s to %s for user %s' %
(edue, unit.location.url(), student.username))
set_due_date_extension(course, unit, student, edue)
......
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