Moved extra settings into state. Added fs module for aux content

This commit is contained in:
Piotr Mitros
2012-05-07 20:13:30 -04:00
parent a0ecbca080
commit e1ac5e9f30
9 changed files with 49 additions and 33 deletions

View File

@@ -18,8 +18,12 @@ from django.http import HttpResponse
from django.shortcuts import redirect
from django.template import Context
from django.template import Context, loader
from fs.osfs import OSFS
from mitxmako.shortcuts import render_to_response, render_to_string
from models import StudentModule
from student.models import UserProfile
import track.views
@@ -30,6 +34,13 @@ import courseware.modules
log = logging.getLogger("mitx.courseware")
class I4xSystem(object):
def __init__(self, **args):
self.ajax_url = args['ajax_url']
self.track_function = args['track_function']
self.filestore = OSFS(settings.DATA_DIR)
self.render_function = args['render_function']
def object_cache(cache, user, module_type, module_id):
# We don't look up on user -- all queries include user
# Additional lookup would require a DB hit the way Django
@@ -76,12 +87,15 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
xml = content_parser.module_xml(request.user, module, 'id', id)
# Create the module
instance=courseware.modules.get_module_class(module)(xml,
system = I4xSystem(track_function = make_track_function(request),
render_function = None,
ajax_url = ajax_url,
filestore = None
)
instance=courseware.modules.get_module_class(module)(system,
xml,
id,
ajax_url=ajax_url,
state=oldstate,
track_function = make_track_function(request),
render_function = None)
state=oldstate)
# Let the module handle the AJAX
ajax_return=instance.handle_ajax(dispatch, request.POST)
# Save the state back to the database
@@ -128,12 +142,15 @@ def render_x_module(user, request, xml_module, module_object_preload):
# Create a new instance
ajax_url = '/modx/'+module_type+'/'+module_id+'/'
instance=module_class(etree.tostring(xml_module),
system = I4xSystem(track_function = make_track_function(request),
render_function = lambda x: render_module(user, request, x, module_object_preload),
ajax_url = ajax_url,
filestore = None
)
instance=module_class(system,
etree.tostring(xml_module),
module_id,
ajax_url=ajax_url,
state=state,
track_function = make_track_function(request),
render_function = lambda x: render_module(user, request, x, module_object_preload))
state=state)
# If instance wasn't already in the database, create it
if not smod: