Commit 91e50f13 by Chris Dodge

implement importing of grading policy during import. This is stored in…

implement importing of grading policy during import. This is stored in definition.data.grading_policy.
parent 44251612
......@@ -11,6 +11,8 @@ from xmodule.modulestore import Location
from xmodule.seq_module import SequenceDescriptor, SequenceModule
from xmodule.timeparse import parse_time, stringify_time
from xmodule.graders import load_grading_policy_from_dict
log = logging.getLogger(__name__)
class CourseDescriptor(SequenceDescriptor):
......@@ -96,6 +98,9 @@ class CourseDescriptor(SequenceDescriptor):
# disable the syllabus content for courses that do not provide a syllabus
self.syllabus_present = self.system.resources_fs.exists(path('syllabus'))
self._grading_policy = load_grading_policy_from_dict(self.definition['data'].get('grading_policy', None))
def set_grading_policy(self, policy_str):
"""Parse the policy specified in policy_str, and save it"""
try:
......@@ -284,3 +289,4 @@ class CourseDescriptor(SequenceDescriptor):
def org(self):
return self.location.org
......@@ -13,6 +13,16 @@ log = logging.getLogger("mitx.courseware")
Score = namedtuple("Score", "earned possible graded section")
def load_grading_policy(course_policy_string):
course_policy = {}
if course_policy_string:
course_policy = json.loads(course_policy_string)
return load_grading_policy_from_dict(course_policy)
def load_grading_policy_from_dict(course_policy):
if course_policy is None:
course_policy = {}
"""
This loads a grading policy from a string (usually read from a file),
which can be a JSON object or an empty string.
......@@ -62,11 +72,6 @@ def load_grading_policy(course_policy_string):
# Load the global settings as a dictionary
grading_policy = json.loads(default_policy_string)
# Load the course policies as a dictionary
course_policy = {}
if course_policy_string:
course_policy = json.loads(course_policy_string)
# Override any global settings with the course settings
grading_policy.update(course_policy)
......@@ -76,6 +81,7 @@ def load_grading_policy(course_policy_string):
return grading_policy
def aggregate_scores(scores, section_name="summary"):
"""
scores: A list of Score objects
......
......@@ -452,6 +452,10 @@ class XMLModuleStore(ModuleStoreBase):
policy_str = self.read_grading_policy(paths, tracker)
course_descriptor.set_grading_policy(policy_str)
# cdodge: import the grading policy information that is on disk and put into the
# descriptor 'definition' bucket as a dictionary so that it is persisted in the DB
course_descriptor.definition['data']['grading_policy'] = json.loads(policy_str)
log.debug('========> Done with course import from {0}'.format(course_dir))
return course_descriptor
......
......@@ -74,11 +74,12 @@ def import_from_xml(store, data_dir, course_dirs=None,
all course dirs
"""
module_store = XMLModuleStore(
data_dir,
default_class=default_class,
course_dirs=course_dirs,
load_error_modules=load_error_modules,
load_error_modules=load_error_modules
)
# NOTE: the XmlModuleStore does not implement get_items() which would be a preferable means
......@@ -121,6 +122,5 @@ def import_from_xml(store, data_dir, course_dirs=None,
# NOTE: It's important to use own_metadata here to avoid writing
# inherited metadata everywhere.
store.update_metadata(module.location, dict(module.own_metadata))
return module_store, course_items
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