made "position" a generic parameter passed to all modules, from courseware.views.index
This commit is contained in:
@@ -38,6 +38,11 @@ class I4xSystem(object):
|
||||
self.render_function = render_function
|
||||
self.exception404 = Http404
|
||||
self.DEBUG = settings.DEBUG
|
||||
|
||||
def get(self,attr): # uniform access to attributes (like etree)
|
||||
return self.__dict__.get(attr)
|
||||
def set(self,attr,val): # uniform access to attributes (like etree)
|
||||
self.__dict__[attr] = val
|
||||
def __repr__(self):
|
||||
return repr(self.__dict__)
|
||||
def __str__(self):
|
||||
@@ -100,7 +105,7 @@ def get_state_from_module_object_preload(user, xml_module, module_object_preload
|
||||
|
||||
return smod, state
|
||||
|
||||
def render_x_module(user, request, xml_module, module_object_preload):
|
||||
def render_x_module(user, request, xml_module, module_object_preload,position=None):
|
||||
''' Generic module for extensions. This renders to HTML.
|
||||
|
||||
modules include sequential, vertical, problem, video, html
|
||||
@@ -113,6 +118,11 @@ def render_x_module(user, request, xml_module, module_object_preload):
|
||||
- request : current django HTTPrequest
|
||||
- xml_module : lxml etree of xml subtree for the current module
|
||||
- module_object_preload : list of StudentModule objects, one of which may match this module type and id
|
||||
- position : extra information from URL for user-specified position within module
|
||||
|
||||
Returns:
|
||||
|
||||
- dict which is context for HTML rendering of the specified module
|
||||
|
||||
'''
|
||||
module_type=xml_module.tag
|
||||
@@ -138,6 +148,7 @@ def render_x_module(user, request, xml_module, module_object_preload):
|
||||
ajax_url = ajax_url,
|
||||
filestore = OSFS(data_root),
|
||||
)
|
||||
system.set('position',position) # pass URL specified position along to module, through I4xSystem
|
||||
instance=module_class(system,
|
||||
etree.tostring(xml_module),
|
||||
module_id,
|
||||
@@ -176,8 +187,22 @@ def render_x_module(user, request, xml_module, module_object_preload):
|
||||
|
||||
return content
|
||||
|
||||
def render_module(user, request, module, module_object_preload):
|
||||
''' Generic dispatch for internal modules. '''
|
||||
def render_module(user, request, module, module_object_preload, position=None):
|
||||
''' Generic dispatch for internal modules.
|
||||
|
||||
Args:
|
||||
|
||||
- user : django User
|
||||
- request : HTTP request
|
||||
- module : ElementTree (xml) for this module
|
||||
- module_object_preload : list of StudentModule objects, one of which may match this module type and id
|
||||
- position : extra information from URL for user-specified position within module
|
||||
|
||||
Returns:
|
||||
|
||||
- dict which is context for HTML rendering of the specified module
|
||||
|
||||
'''
|
||||
if module==None :
|
||||
return {"content":""}
|
||||
return render_x_module(user, request, module, module_object_preload)
|
||||
return render_x_module(user, request, module, module_object_preload, position)
|
||||
|
||||
@@ -113,4 +113,8 @@ class Module(XModule):
|
||||
state = json.loads(state)
|
||||
if 'position' in state: self.position = int(state['position'])
|
||||
|
||||
# if position is specified in system, then use that instead
|
||||
if system.get('position'):
|
||||
self.position = int(system.get('position'))
|
||||
|
||||
self.rendered = False
|
||||
|
||||
@@ -68,6 +68,7 @@ class XModule(object):
|
||||
self.xml = xml
|
||||
self.item_id = item_id
|
||||
self.state = state
|
||||
self.DEBUG = False
|
||||
|
||||
if system:
|
||||
## These are temporary; we really should go
|
||||
@@ -76,4 +77,5 @@ class XModule(object):
|
||||
self.tracker = system.track_function
|
||||
self.filestore = system.filestore
|
||||
self.render_function = system.render_function
|
||||
self.DEBUG = system.DEBUG
|
||||
self.system = system
|
||||
|
||||
@@ -160,7 +160,11 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
|
||||
- course : coursename (str)
|
||||
- chapter : chapter name (str)
|
||||
- section : section name (str)
|
||||
- position : position in sequence, ie of <sequential> module (int)
|
||||
- position : position in module, eg of <sequential> module (str)
|
||||
|
||||
Returns:
|
||||
|
||||
- HTTPresponse
|
||||
|
||||
'''
|
||||
user = request.user
|
||||
@@ -215,21 +219,6 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
|
||||
else:
|
||||
module_object_preload = []
|
||||
|
||||
if position and module and module.tag=='sequential':
|
||||
smod, state = get_state_from_module_object_preload(user, module, module_object_preload)
|
||||
newstate = json.dumps({ 'position':position })
|
||||
if smod:
|
||||
smod.state = newstate
|
||||
elif user.is_authenticated():
|
||||
smod=StudentModule(student=user,
|
||||
module_type = module.tag,
|
||||
module_id= module.get('id'),
|
||||
state = newstate)
|
||||
smod.save()
|
||||
# now regenerate module_object_preload
|
||||
module_object_preload = list(StudentModule.objects.filter(student=user,
|
||||
module_id__in=module_ids))
|
||||
|
||||
context = {
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'accordion': render_accordion(request, course, chapter, section),
|
||||
@@ -237,7 +226,7 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
|
||||
}
|
||||
|
||||
try:
|
||||
module = render_module(user, request, module, module_object_preload) # ugh - shouldn't overload module
|
||||
module_context = render_module(user, request, module, module_object_preload, position)
|
||||
except:
|
||||
log.exception("Unable to load module")
|
||||
context.update({
|
||||
@@ -247,8 +236,8 @@ def index(request, course=None, chapter="Using the System", section="Hints",posi
|
||||
return render_to_response('courseware.html', context)
|
||||
|
||||
context.update({
|
||||
'init': module.get('init_js', ''),
|
||||
'content': module['content'],
|
||||
'init': module_context.get('init_js', ''),
|
||||
'content': module_context['content'],
|
||||
})
|
||||
|
||||
result = render_to_response('courseware.html', context)
|
||||
|
||||
Reference in New Issue
Block a user