Commit e77a67a9 by cahrens

Protect against graceperiodjson being null.

r.don
parent aee4fd91
from xmodule.modulestore import Location from xmodule.modulestore import Location
from contentstore.utils import get_modulestore from contentstore.utils import get_modulestore
import datetime
import re import re
from util import converters from util import converters
import time
class CourseGradingModel: class CourseGradingModel:
...@@ -145,19 +143,23 @@ class CourseGradingModel: ...@@ -145,19 +143,23 @@ class CourseGradingModel:
def update_grace_period_from_json(course_location, graceperiodjson): def update_grace_period_from_json(course_location, graceperiodjson):
""" """
Update the course's default grace period. Incoming dict is {hours: h, minutes: m} possibly as a Update the course's default grace period. Incoming dict is {hours: h, minutes: m} possibly as a
grace_period entry in an enclosing dict. grace_period entry in an enclosing dict. It is also safe to call this method with a value of
None for graceperiodjson.
""" """
if not isinstance(course_location, Location): if not isinstance(course_location, Location):
course_location = Location(course_location) course_location = Location(course_location)
if 'grace_period' in graceperiodjson: # Before a graceperiod has ever been created, it will be None (once it has been
graceperiodjson = graceperiodjson['grace_period'] # created, it cannot be set back to None).
if graceperiodjson is not None:
grace_rep = " ".join(["%s %s" % (value, key) for (key, value) in graceperiodjson.iteritems()]) if 'grace_period' in graceperiodjson:
graceperiodjson = graceperiodjson['grace_period']
descriptor = get_modulestore(course_location).get_item(course_location)
descriptor.metadata['graceperiod'] = grace_rep grace_rep = " ".join(["%s %s" % (value, key) for (key, value) in graceperiodjson.iteritems()])
get_modulestore(course_location).update_metadata(course_location, descriptor.metadata)
descriptor = get_modulestore(course_location).get_item(course_location)
descriptor.metadata['graceperiod'] = grace_rep
get_modulestore(course_location).update_metadata(course_location, descriptor.metadata)
@staticmethod @staticmethod
def delete_grader(course_location, index): def delete_grader(course_location, index):
...@@ -171,7 +173,7 @@ class CourseGradingModel: ...@@ -171,7 +173,7 @@ class CourseGradingModel:
index = int(index) index = int(index)
if index < len(descriptor.raw_grader): if index < len(descriptor.raw_grader):
del descriptor.raw_grader[index] del descriptor.raw_grader[index]
# force propagation to defintion # force propagation to definition
descriptor.raw_grader = descriptor.raw_grader descriptor.raw_grader = descriptor.raw_grader
get_modulestore(course_location).update_item(course_location, descriptor.definition['data']) get_modulestore(course_location).update_item(course_location, descriptor.definition['data'])
......
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