diff --git a/common/lib/xmodule/xmodule/modulestore/__init__.py b/common/lib/xmodule/xmodule/modulestore/__init__.py index e59e4bd68e..6c77127d7e 100644 --- a/common/lib/xmodule/xmodule/modulestore/__init__.py +++ b/common/lib/xmodule/xmodule/modulestore/__init__.py @@ -190,6 +190,13 @@ class Location(_LocationBase): return "Location%s" % repr(tuple(self)) + @property + def course_id(self): + """Return the ID of the Course that this item belongs to by looking + at the location URL hierachy""" + return "/".join([self.org, self.course, self.name]) + + class ModuleStore(object): """ An abstract interface for a database backend that stores XModuleDescriptor diff --git a/lms/djangoapps/courseware/module_render.py b/lms/djangoapps/courseware/module_render.py index 852e3d8a77..ad656f8980 100644 --- a/lms/djangoapps/courseware/module_render.py +++ b/lms/djangoapps/courseware/module_render.py @@ -2,6 +2,7 @@ import json import logging from django.conf import settings +from django.core.urlresolvers import reverse from django.http import Http404 from django.http import HttpResponse from django.views.decorators.csrf import csrf_exempt @@ -125,7 +126,7 @@ 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 @@ -146,7 +147,14 @@ def get_module(user, request, location, student_module_cache, position=None): # TODO (vshnayder): fix hardcoded urls (use reverse) # Setup system context for module instance - ajax_url = settings.MITX_ROOT_URL + '/modx/' + descriptor.location.url() + '/' + + ajax_url = reverse('modx_dispatch', + kwargs=dict(course_id=descriptor.location.course_id, + id=descriptor.location.url(), + dispatch=''), + ) + + # ajax_url = settings.MITX_ROOT_URL + '/modx/' + descriptor.location.url() + '/' # Fully qualified callback URL for external queueing system xqueue_callback_url = (request.build_absolute_uri('/') + settings.MITX_ROOT_URL + @@ -308,7 +316,7 @@ def xqueue_callback(request, userid, id, dispatch): return HttpResponse("") -def modx_dispatch(request, dispatch=None, id=None): +def modx_dispatch(request, dispatch=None, id=None, course_id=None): ''' Generic view for extensions. This is where AJAX calls go. Arguments: diff --git a/lms/urls.py b/lms/urls.py index bb3952b73c..c6cecb74d5 100644 --- a/lms/urls.py +++ b/lms/urls.py @@ -2,7 +2,6 @@ from django.conf import settings from django.conf.urls import patterns, include, url from django.contrib import admin from django.conf.urls.static import static - import django.contrib.auth.views # Uncomment the next two lines to enable the admin: @@ -101,7 +100,9 @@ if settings.COURSEWARE_ENABLED: url(r'^masquerade/', include('masquerade.urls')), url(r'^jump_to/(?P.*)$', 'courseware.views.jump_to', name="jump_to"), - url(r'^modx/(?P.*?)/(?P[^/]*)$', 'courseware.module_render.modx_dispatch'), #reset_problem'), + url(r'^courses/(?P[^/]+/[^/]+/[^/]+)/modx/(?P.*?)/(?P[^/]*)$', + 'courseware.module_render.modx_dispatch', + name='modx_dispatch'), url(r'^xqueue/(?P[^/]*)/(?P.*?)/(?P[^/]*)$', 'courseware.module_render.xqueue_callback'), url(r'^change_setting$', 'student.views.change_setting'),