From 35af8101d763952eeb3983883609e27e78db4638 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 28 Jun 2012 13:40:37 -0400 Subject: [PATCH] Make grade graph on profile work correctly --- common/lib/xmodule/translation_module.py | 2 -- common/lib/xmodule/x_module.py | 11 ++++++++++- common/lib/xmodule/xml_module.py | 4 +++- lms/djangoapps/courseware/grades.py | 8 +++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/common/lib/xmodule/translation_module.py b/common/lib/xmodule/translation_module.py index 6c358d4eaa..d379ced507 100644 --- a/common/lib/xmodule/translation_module.py +++ b/common/lib/xmodule/translation_module.py @@ -57,8 +57,6 @@ class SemanticSectionDescriptor(XModuleDescriptor): if len(xml_object) == 1: for (key, val) in xml_object.items(): - if key == 'format': - continue xml_object[0].set(key, val) return system.process_xml(etree.tostring(xml_object[0])) diff --git a/common/lib/xmodule/x_module.py b/common/lib/xmodule/x_module.py index 71d069fdbe..8ee3df38ff 100644 --- a/common/lib/xmodule/x_module.py +++ b/common/lib/xmodule/x_module.py @@ -85,6 +85,8 @@ class XModule(object): self.display_name = kwargs.get('display_name', '') self.type = self.location.category self._loaded_children = None + self.graded = kwargs.get('graded', False) + self.format = kwargs.get('format') def get_name(self): name = self.__xmltree.get('name') @@ -281,6 +283,9 @@ class XModuleDescriptor(Plugin): Current arguments passed in kwargs: location: A keystore.Location object indicating the name and ownership of this problem goals: A list of strings of learning goals associated with this module + display_name: The name to use for displaying this module to the user + format: The format of this module ('Homework', 'Lab', etc) + graded (bool): Whether this module is should be graded or not """ self.system = system self.definition = definition if definition is not None else {} @@ -288,6 +293,8 @@ class XModuleDescriptor(Plugin): self.type = Location(kwargs.get('location')).category self.url = Location(kwargs.get('location')).url() self.display_name = kwargs.get('display_name') + self.format = kwargs.get('format') + self.graded = kwargs.get('graded', False) # For now, we represent goals as a list of strings, but this # is one of the things that we are going to be iterating on heavily @@ -315,7 +322,9 @@ class XModuleDescriptor(Plugin): instance_state and shared_state, and returns a fully nstantiated XModule """ return partial(self.module_class, system, self.url, self.definition, - display_name=self.display_name) + display_name=self.display_name, + format=self.format, + graded=self.graded) class DescriptorSystem(object): def __init__(self, load_item, resources_fs): diff --git a/common/lib/xmodule/xml_module.py b/common/lib/xmodule/xml_module.py index 34881a4d61..d62957c3d3 100644 --- a/common/lib/xmodule/xml_module.py +++ b/common/lib/xmodule/xml_module.py @@ -37,5 +37,7 @@ class XmlDescriptor(XModuleDescriptor): course, xml_object.tag, xml_object.get('slug')], - display_name=xml_object.get('name') + display_name=xml_object.get('name'), + format=xml_object.get('format'), + graded=xml_object.get('graded') == 'true', ) diff --git a/lms/djangoapps/courseware/grades.py b/lms/djangoapps/courseware/grades.py index 6f6ff71d35..b5fcae86e5 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -92,6 +92,9 @@ def grade_sheet(student, course, student_module_cache): for module in yield_descendents(s): (correct, total) = get_score(student, module, student_module_cache) + if correct is None and total is None: + continue + if settings.GENERATE_PROFILE_SCORES: if total > 1: correct = random.randrange(max(total - 2, 1), total + 1) @@ -102,14 +105,13 @@ def grade_sheet(student, course, student_module_cache): #We simply cannot grade a problem that is 12/0, because we might need it as a percentage graded = False - if correct is not None and total is not None: - scores.append(Score(correct, total, graded, module.display_name)) + scores.append(Score(correct, total, graded, module.display_name)) section_total, graded_total = graders.aggregate_scores(scores, s.display_name) #Add the graded total to totaled_scores format = getattr(s, 'format', "") subtitle = getattr(s, 'subtitle', format) - if format and graded_total[1] > 0: + if format and graded_total.possible > 0: format_scores = totaled_scores.get(format, []) format_scores.append(graded_total) totaled_scores[format] = format_scores