Commit 4ce08cc3 by Calen Pennington

Merge pull request #118 from MITx/victor/render-path-cleanup

Small cleanups in response to Calen + Piotr's comments
parents 5ae2668e 96cbb3d3
...@@ -29,6 +29,9 @@ class I4xSystem(object): ...@@ -29,6 +29,9 @@ class I4xSystem(object):
I4xSystem objects are passed to x_modules to provide access to system I4xSystem objects are passed to x_modules to provide access to system
functionality. functionality.
Note that these functions can be closures over e.g. a django request
and user, or other environment-specific info.
''' '''
def __init__(self, ajax_url, track_function, render_function, def __init__(self, ajax_url, track_function, render_function,
render_template, request=None, filestore=None): render_template, request=None, filestore=None):
...@@ -93,12 +96,9 @@ def smod_cache_lookup(cache, module_type, module_id): ...@@ -93,12 +96,9 @@ def smod_cache_lookup(cache, module_type, module_id):
return None return None
def make_track_function(request): def make_track_function(request):
''' We want the capa problem (and other modules) to be able to '''
track/log what happens inside them without adding dependencies on Make a tracking function that logs what happened.
Django or the rest of the codebase. For use in I4xSystem.
To do this in a clean way, we pass a tracking function to the module,
which calls it to log events.
''' '''
import track.views import track.views
...@@ -164,11 +164,11 @@ def get_module(user, request, module_xml, student_module_cache, position=None): ...@@ -164,11 +164,11 @@ def get_module(user, request, module_xml, student_module_cache, position=None):
# Setup system context for module instance # Setup system context for module instance
ajax_url = settings.MITX_ROOT_URL + '/modx/' + module_type + '/' + module_id + '/' ajax_url = settings.MITX_ROOT_URL + '/modx/' + module_type + '/' + module_id + '/'
def render_function(module_xml): def render_x_module_wrapper(module_xml):
return render_x_module(user, request, module_xml, student_module_cache, position) return render_x_module(user, request, module_xml, student_module_cache, position)
system = I4xSystem(track_function = make_track_function(request), system = I4xSystem(track_function = make_track_function(request),
render_function = render_function, render_function = render_x_module_wrapper,
render_template = render_to_string, render_template = render_to_string,
ajax_url = ajax_url, ajax_url = ajax_url,
request = request, request = request,
...@@ -254,7 +254,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -254,7 +254,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
return redirect('/') return redirect('/')
# python concats adjacent strings # python concats adjacent strings
error_msg = ("We're sorry, this module is temporarily unavailable." error_msg = ("We're sorry, this module is temporarily unavailable. "
"Our staff is working to fix it as soon as possible") "Our staff is working to fix it as soon as possible")
...@@ -262,7 +262,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -262,7 +262,6 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
s = StudentModule.objects.filter(student=request.user, s = StudentModule.objects.filter(student=request.user,
module_id=id) module_id=id)
# s = StudentModule.get_with_caching(request.user, id)
if s is None or len(s) == 0: if s is None or len(s) == 0:
log.debug("Couldn't find module '%s' for user '%s' and id '%s'", log.debug("Couldn't find module '%s' for user '%s' and id '%s'",
module, request.user, id) module, request.user, id)
...@@ -273,8 +272,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None): ...@@ -273,8 +272,7 @@ def modx_dispatch(request, module=None, dispatch=None, id=None):
oldstate = s.state oldstate = s.state
# If there are arguments, get rid of them # If there are arguments, get rid of them
if '?' in dispatch: dispatch, _, _ = dispatch.partition('?')
dispatch = dispatch.split('?')[0]
ajax_url = '{root}/modx/{module}/{id}'.format(root = settings.MITX_ROOT_URL, ajax_url = '{root}/modx/{module}/{id}'.format(root = settings.MITX_ROOT_URL,
module=module, id=id) module=module, id=id)
......
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