courseware.get_module passes down course_id triplet (org, course, run)
This commit is contained in:
@@ -48,7 +48,7 @@ def make_track_function(request):
|
||||
return f
|
||||
|
||||
|
||||
def toc_for_course(user, request, course, active_chapter, active_section):
|
||||
def toc_for_course(user, request, course, active_chapter, active_section, course_id=None):
|
||||
'''
|
||||
Create a table of contents from the module store
|
||||
|
||||
@@ -71,7 +71,7 @@ def toc_for_course(user, request, course, active_chapter, active_section):
|
||||
'''
|
||||
|
||||
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(user, course, depth=2)
|
||||
course = get_module(user, request, course.location, student_module_cache)
|
||||
course = get_module(user, request, course.location, student_module_cache, course_id=course_id)
|
||||
|
||||
chapters = list()
|
||||
for chapter in course.get_display_items():
|
||||
@@ -127,7 +127,7 @@ def get_section(course_module, chapter, section):
|
||||
return section_module
|
||||
|
||||
|
||||
def get_module(user, request, location, student_module_cache, position=None):
|
||||
def get_module(user, request, location, student_module_cache, position=None, course_id=None):
|
||||
''' Get an instance of the xmodule class identified by location,
|
||||
setting the state based on an existing StudentModule, or creating one if none
|
||||
exists.
|
||||
@@ -144,6 +144,14 @@ def get_module(user, request, location, student_module_cache, position=None):
|
||||
|
||||
'''
|
||||
descriptor = modulestore().get_item(location)
|
||||
|
||||
# NOTE:
|
||||
# A 'course_id' is understood to be the triplet (org, course, run), for example
|
||||
# (MITx, 6.002x, 2012_Spring).
|
||||
# At the moment generic XModule does not contain enough information to replicate
|
||||
# the triplet (it is missing 'run'), so we must pass down course_id
|
||||
if course_id is None:
|
||||
course_id = descriptor.location.course_id # Will NOT produce (org, course, run) for non-CourseModule's
|
||||
|
||||
# Short circuit--if the user shouldn't have access, bail without doing any work
|
||||
if not has_access(user, descriptor, 'load'):
|
||||
@@ -167,7 +175,7 @@ def get_module(user, request, location, student_module_cache, position=None):
|
||||
|
||||
# Setup system context for module instance
|
||||
ajax_url = reverse('modx_dispatch',
|
||||
kwargs=dict(course_id=descriptor.location.course_id,
|
||||
kwargs=dict(course_id=course_id,
|
||||
id=descriptor.location.url(),
|
||||
dispatch=''),
|
||||
)
|
||||
@@ -175,7 +183,7 @@ def get_module(user, request, location, student_module_cache, position=None):
|
||||
# Fully qualified callback URL for external queueing system
|
||||
xqueue_callback_url = request.build_absolute_uri('/')[:-1] # Trailing slash provided by reverse
|
||||
xqueue_callback_url += reverse('xqueue_callback',
|
||||
kwargs=dict(course_id=descriptor.location.course_id,
|
||||
kwargs=dict(course_id=course_id,
|
||||
userid=str(user.id),
|
||||
id=descriptor.location.url(),
|
||||
dispatch='score_update'),
|
||||
@@ -195,7 +203,7 @@ def get_module(user, request, location, student_module_cache, position=None):
|
||||
Delegate to get_module. It does an access check, so may return None
|
||||
"""
|
||||
return get_module(user, request, location,
|
||||
student_module_cache, position)
|
||||
student_module_cache, position, course_id=course_id)
|
||||
|
||||
# TODO (cpennington): When modules are shared between courses, the static
|
||||
# prefix is going to have to be specific to the module, not the directory
|
||||
@@ -309,7 +317,7 @@ def xqueue_callback(request, course_id, userid, id, dispatch):
|
||||
|
||||
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(
|
||||
user, modulestore().get_item(id), depth=0, acquire_lock=True)
|
||||
instance = get_module(user, request, id, student_module_cache)
|
||||
instance = get_module(user, request, id, student_module_cache, course_id=course_id)
|
||||
if instance is None:
|
||||
log.debug("No module {} for user {}--access denied?".format(id, user))
|
||||
raise Http404
|
||||
@@ -370,7 +378,7 @@ def modx_dispatch(request, dispatch=None, id=None, course_id=None):
|
||||
p[inputfile_id] = inputfile
|
||||
|
||||
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(request.user, modulestore().get_item(id))
|
||||
instance = get_module(request.user, request, id, student_module_cache)
|
||||
instance = get_module(request.user, request, id, student_module_cache, course_id=course_id)
|
||||
if instance is None:
|
||||
# Either permissions just changed, or someone is trying to be clever
|
||||
# and load something they shouldn't have access to.
|
||||
|
||||
@@ -35,19 +35,6 @@ log = logging.getLogger("mitx.courseware")
|
||||
template_imports = {'urllib': urllib}
|
||||
|
||||
|
||||
def course_redirect(request, course_path):
|
||||
'''
|
||||
Allows course XML to refer to its own directory structure without knowing the multicourse hierarchy.
|
||||
Prepends the multicourse path to the requested course-internal path.
|
||||
If the course_id cannot be determined, redirect to multicourse page. (NOTE: is Http404 more appropriate?)
|
||||
'''
|
||||
referer = request.META['HTTP_REFERER']
|
||||
match = re.search(r'/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/', referer)
|
||||
courses_path = '/courses/'
|
||||
if match is not None:
|
||||
courses_path += match.group('course_id') + '/' + course_path
|
||||
return HttpResponseRedirect(courses_path)
|
||||
|
||||
def user_groups(user):
|
||||
"""
|
||||
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
|
||||
@@ -82,7 +69,7 @@ def courses(request):
|
||||
return render_to_response("courses.html", {'universities': universities})
|
||||
|
||||
|
||||
def render_accordion(request, course, chapter, section):
|
||||
def render_accordion(request, course, chapter, section, course_id=None):
|
||||
''' Draws navigation bar. Takes current position in accordion as
|
||||
parameter.
|
||||
|
||||
@@ -93,7 +80,7 @@ def render_accordion(request, course, chapter, section):
|
||||
Returns the html string'''
|
||||
|
||||
# grab the table of contents
|
||||
toc = toc_for_course(request.user, request, course, chapter, section)
|
||||
toc = toc_for_course(request.user, request, course, chapter, section, course_id=course_id)
|
||||
|
||||
context = dict([('toc', toc),
|
||||
('course_id', course.id),
|
||||
@@ -134,7 +121,7 @@ def index(request, course_id, chapter=None, section=None,
|
||||
try:
|
||||
context = {
|
||||
'csrf': csrf(request)['csrf_token'],
|
||||
'accordion': render_accordion(request, course, chapter, section),
|
||||
'accordion': render_accordion(request, course, chapter, section, course_id=course_id),
|
||||
'COURSE_TITLE': course.title,
|
||||
'course': course,
|
||||
'init': '',
|
||||
@@ -150,7 +137,7 @@ def index(request, course_id, chapter=None, section=None,
|
||||
section_descriptor)
|
||||
module = get_module(request.user, request,
|
||||
section_descriptor.location,
|
||||
student_module_cache)
|
||||
student_module_cache, course_id=course_id)
|
||||
if module is None:
|
||||
# User is probably being clever and trying to access something
|
||||
# they don't have access to.
|
||||
@@ -285,7 +272,7 @@ def profile(request, course_id, student_id=None):
|
||||
user_info = UserProfile.objects.get(user=student)
|
||||
|
||||
student_module_cache = StudentModuleCache.cache_for_descriptor_descendents(request.user, course)
|
||||
course_module = get_module(request.user, request, course.location, student_module_cache)
|
||||
course_module = get_module(request.user, request, course.location, student_module_cache, course_id=course_id)
|
||||
|
||||
courseware_summary = grades.progress_summary(student, course_module, course.grader, student_module_cache)
|
||||
grade_summary = grades.grade(request.user, request, course, student_module_cache)
|
||||
|
||||
@@ -124,7 +124,6 @@ if settings.COURSEWARE_ENABLED:
|
||||
'courseware.views.course_about', name="about_course"),
|
||||
|
||||
#Inside the course
|
||||
url(r'^course/(?P<course_path>.*)$','courseware.views.course_redirect'),
|
||||
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/info$',
|
||||
'courseware.views.course_info', name="info"),
|
||||
url(r'^courses/(?P<course_id>[^/]+/[^/]+/[^/]+)/book$',
|
||||
|
||||
Reference in New Issue
Block a user