diff --git a/common/lib/xmodule/xmodule/capa_module.py b/common/lib/xmodule/xmodule/capa_module.py index 02717884bb..2af40fbbed 100644 --- a/common/lib/xmodule/xmodule/capa_module.py +++ b/common/lib/xmodule/xmodule/capa_module.py @@ -562,6 +562,8 @@ class CapaDescriptor(RawDescriptor): """ module_class = CapaModule + + stores_state = True # VS[compat] # TODO (cpennington): Delete this method once all fall 2012 course are being diff --git a/common/lib/xmodule/xmodule/seq_module.py b/common/lib/xmodule/xmodule/seq_module.py index 5bef8596c2..2e5b799d3b 100644 --- a/common/lib/xmodule/xmodule/seq_module.py +++ b/common/lib/xmodule/xmodule/seq_module.py @@ -107,6 +107,8 @@ class SequenceModule(XModule): class SequenceDescriptor(MakoModuleDescriptor, XmlDescriptor): mako_template = 'widgets/sequence-edit.html' module_class = SequenceModule + + stores_state = True # For remembering where in the sequence the student is @classmethod def definition_from_xml(cls, xml_object, system): diff --git a/common/lib/xmodule/xmodule/video_module.py b/common/lib/xmodule/xmodule/video_module.py index ec3a99584d..7d11dea283 100644 --- a/common/lib/xmodule/xmodule/video_module.py +++ b/common/lib/xmodule/xmodule/video_module.py @@ -80,3 +80,5 @@ class VideoModule(XModule): class VideoDescriptor(RawDescriptor): module_class = VideoModule + + stores_state = True diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index deac250e9d..cfb1a664b0 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -303,6 +303,10 @@ class XModuleDescriptor(Plugin, HTMLSnippet): """ entry_point = "xmodule.v1" module_class = XModule + + # Attributes for inpsection of the descriptor + stores_state = False # Indicates wether the xmodule state should be + # stored in a database (independent of shared state) # 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 925b8429c6..926040ab6f 100644 --- a/lms/djangoapps/courseware/grades.py +++ b/lms/djangoapps/courseware/grades.py @@ -183,6 +183,10 @@ 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 + return (None, None) + correct = 0.0 # If the ID is not in the cache, add the item diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index 631a750643..aa9f946733 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -69,10 +69,10 @@ class StudentModuleCache(object): """ def __init__(self, user, descriptors): ''' - Find any StudentModule objects that are needed by any child modules of the - supplied descriptor, or caches only the StudentModule objects specifically - for every descriptor in descriptors. Avoids making multiple queries to the - database. + Find any StudentModule objects that are needed by any descriptor + in descriptors. Avoids making multiple queries to the database. + Note: Only modules that have store_state = True or have shared + state will have a StudentModule. Arguments user: The user for which to fetch maching StudentModules @@ -134,7 +134,8 @@ class StudentModuleCache(object): ''' keys = [] for descriptor in descriptors: - keys.append(descriptor.location.url()) + if descriptor.stores_state: + keys.append(descriptor.location.url()) shared_state_key = getattr(descriptor, 'shared_state_key', None) if shared_state_key is not None: diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 5e74e6f42e..d60192fa31 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -127,19 +127,18 @@ def get_module(user, request, location, student_module_cache, position=None): descriptor = modulestore().get_item(location) #TODO Only check the cache if this module can possibly have state + instance_module = None + shared_module = None if user.is_authenticated(): - instance_module = student_module_cache.lookup(descriptor.category, - descriptor.location.url()) + if descriptor.stores_state: + instance_module = student_module_cache.lookup(descriptor.category, + descriptor.location.url()) shared_state_key = getattr(descriptor, 'shared_state_key', None) if shared_state_key is not None: shared_module = student_module_cache.lookup(descriptor.category, shared_state_key) - else: - shared_module = None - else: - instance_module = None - shared_module = None + instance_state = instance_module.state if instance_module is not None else None @@ -206,6 +205,11 @@ def get_instance_module(user, module, student_module_cache): or None if this is an anonymous user """ if user.is_authenticated(): + if not module.descriptor.stores_state: + log.exception("Attempted to get the instance_module for a module " + + str(module.id) + " which does not store state.") + return None + instance_module = student_module_cache.lookup(module.category, module.location.url())