Commit 638a5059 by Bridger Maxwell

Added stores_state attribute for xmoduledescriptors as a way to declare if the…

Added stores_state attribute for xmoduledescriptors as a way to declare if the module stores state in the database.
parent f872e41d
......@@ -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
......
......@@ -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):
......
......@@ -80,3 +80,5 @@ class VideoModule(XModule):
class VideoDescriptor(RawDescriptor):
module_class = VideoModule
stores_state = True
......@@ -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 = (
......
......@@ -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
......
......@@ -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:
......
......@@ -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())
......
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