From a9d67c3e8d4276ae59cc00a79dd9ecb6baff74c8 Mon Sep 17 00:00:00 2001 From: Bridger Maxwell Date: Tue, 7 Aug 2012 15:20:47 -0400 Subject: [PATCH] Added has_score attribute to xmodule, for problem-like xmodules. --- common/lib/xmodule/xmodule/capa_module.py | 1 + common/lib/xmodule/xmodule/course_module.py | 8 ++++---- common/lib/xmodule/xmodule/x_module.py | 3 +++ lms/djangoapps/courseware/grades.py | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 7ca33841dc..5501d6301c 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -564,6 +564,7 @@ class CapaDescriptor(RawDescriptor): module_class = CapaModule stores_state = True + has_score = True # Capa modules have some additional metadata: # TODO (vshnayder): do problems have any other metadata? Do they diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index ce1b93aa44..7ec9f54cd2 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -99,10 +99,10 @@ class CourseDescriptor(SequenceDescriptor): sections = [] for s in c.get_children(): if s.metadata.get('graded', False): - # TODO: Only include modules that have a score here - xmoduledescriptors = [child for child in yield_descriptor_descendents(s)] - - section_description = { 'section_descriptor' : s, 'xmoduledescriptors' : xmoduledescriptors} + xmoduledescriptors = list(yield_descriptor_descendents(s)) + + # The xmoduledescriptors included here are only the ones that have scores. + section_description = { 'section_descriptor' : s, 'xmoduledescriptors' : filter(lambda child: child.has_score, xmoduledescriptors) } section_format = s.metadata.get('format', "") graded_sections[ section_format ] = graded_sections.get( section_format, [] ) + [section_description] diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 9ed1854c5b..7bc8a72731 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -308,6 +308,9 @@ class XModuleDescriptor(Plugin, HTMLSnippet): # Attributes for inpsection of the descriptor stores_state = False # Indicates wether the xmodule state should be # stored in a database (independent of shared state) + has_score = False # This indicates whether the xmodule is a problem-type. + # It should respond to max_score() and grade(). It can be graded or ungraded + # (like a practice problem). # A list of metadata that this module can inherit from its parent module inheritable_metadata = ( diff --git a/lms/djangoapps/courseware/grades.py b/lms/djangoapps/courseware/grades.py index 926040ab6f..737e4245e0 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -183,8 +183,8 @@ def get_score(user, problem, student_module_cache): problem: an XModule cache: A StudentModuleCache """ - if not problem.descriptor.stores_state: - # These are not problems, and do not store state + if not problem.descriptor.stores_state or not problem.descriptor.has_score: + # These are not problems, and do not have a score return (None, None) correct = 0.0