Commit b11f0e17 by Brian Wilson

respond to feedback

parent b6f95c71
......@@ -54,55 +54,28 @@ class Command(BaseCommand):
dest='save_changes',
default=False,
help='Persist the changes that were encountered. If not set, no changes are saved.'),
make_option('--idlist',
action='store',
dest='idlist_path',
help='Path containing id values of StudentModule objects to clean (one per line).'),
)
# DON'T DO THIS:
# def fix_studentmodules(self, save_changes):
# '''Identify the list of StudentModule objects that might need fixing, and then fix each one'''
# modules = StudentModule.objects.filter(modified__gt='2013-03-28 22:00:00',
# created__lt='2013-03-29 16:30:00',
# state__contains='input_state')
#
# for module in modules:
# self.remove_studentmodule_input_state(module, save_changes)
#
# LOG.info("Finished student modules: updating {0} of {1} modules".format(self.num_changed, self.num_visited))
#
# hist_modules = StudentModuleHistory.objects.filter(created__gt='2013-03-28 22:00:00',
# created__lt='2013-03-29 16:30:00',
# state__contains='input_state')
#
# for hist_module in hist_modules:
# self.remove_studentmodulehistory_input_state(hist_module, save_changes)
#
# LOG.info("Finished student history modules: updating {0} of {1} modules".format(self.num_hist_changed, self.num_hist_visited))
def fix_studentmodules_in_list(self, save_changes, idlist_path):
'''Read in the list of StudentModule objects that might need fixing, and then fix each one'''
# open file and read id values from it:
for line in open(idlist_path, 'r'):
student_module_id = line.strip()
# skip the header, if present:
if student_module_id == 'id':
continue
try:
module = StudentModule.objects.get(id=student_module_id)
except:
except StudentModule.DoesNotExist:
LOG.error("Unable to find student module with id = {0}: skipping... ".format(student_module_id))
continue
self.remove_studentmodule_input_state(module, save_changes)
hist_modules = StudentModuleHistory.objects.filter(student_module_id = student_module_id)
hist_modules = StudentModuleHistory.objects.filter(student_module_id=student_module_id)
for hist_module in hist_modules:
self.remove_studentmodulehistory_input_state(hist_module, save_changes)
LOG.info("Finished student modules: updating {0} of {1} modules".format(self.num_changed, self.num_visited))
LOG.info("Finished student history modules: updating {0} of {1} modules".format(self.num_hist_changed, self.num_hist_visited))
@transaction.autocommit
def remove_studentmodule_input_state(self, module, save_changes):
''' Fix the grade assigned to a StudentModule'''
......@@ -166,4 +139,5 @@ class Command(BaseCommand):
self.fix_studentmodules_in_list(save_changes, idlist_path)
LOG.info("Finished run: updating {0} of {1} student modules".format(self.num_changed, self.num_visited))
LOG.info("Finished run: updating {0} of {1} student history modules".format(self.num_hist_changed, self.num_hist_visited))
LOG.info("Finished run: updating {0} of {1} student history modules".format(self.num_hist_changed,
self.num_hist_visited))
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