Fix Next Button's 404 error
MA-2305
This commit is contained in:
committed by
Clinton Blackburn
parent
04cf9ae8b0
commit
3be03d4677
@@ -147,7 +147,7 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
user, request, course, field_data_cache, course.id, course=course
|
||||
)
|
||||
if course_module is None:
|
||||
return None
|
||||
return None, None, None
|
||||
|
||||
toc_chapters = list()
|
||||
chapters = course_module.get_display_items()
|
||||
@@ -163,9 +163,12 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
if not user_must_complete_entrance_exam(request, user, course):
|
||||
required_content = [content for content in required_content if not content == course.entrance_exam_id]
|
||||
|
||||
previous_of_active_section, next_of_active_section = None, None
|
||||
last_processed_section, last_processed_chapter = None, None
|
||||
found_active_section = False
|
||||
for chapter in chapters:
|
||||
# Only show required content, if there is required content
|
||||
# chapter.hide_from_toc is read-only (boo)
|
||||
# chapter.hide_from_toc is read-only (bool)
|
||||
display_id = slugify(chapter.display_name_with_default_escaped)
|
||||
local_hide_from_toc = False
|
||||
if required_content:
|
||||
@@ -178,78 +181,39 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
|
||||
sections = list()
|
||||
for section in chapter.get_display_items():
|
||||
|
||||
active = (chapter.url_name == active_chapter and
|
||||
section.url_name == active_section)
|
||||
|
||||
# Skip the current section if it is gated
|
||||
# skip the section if it is gated/hidden from the user
|
||||
if gated_content and unicode(section.location) in gated_content:
|
||||
continue
|
||||
if section.hide_from_toc:
|
||||
continue
|
||||
|
||||
if not section.hide_from_toc:
|
||||
section_context = {
|
||||
'display_name': section.display_name_with_default_escaped,
|
||||
'url_name': section.url_name,
|
||||
'format': section.format if section.format is not None else '',
|
||||
'due': section.due,
|
||||
'active': active,
|
||||
'graded': section.graded,
|
||||
}
|
||||
is_section_active = (chapter.url_name == active_chapter and section.url_name == active_section)
|
||||
if is_section_active:
|
||||
found_active_section = True
|
||||
|
||||
#
|
||||
# Add in rendering context if exam is a timed exam (which includes proctored)
|
||||
#
|
||||
section_context = {
|
||||
'display_name': section.display_name_with_default_escaped,
|
||||
'url_name': section.url_name,
|
||||
'format': section.format if section.format is not None else '',
|
||||
'due': section.due,
|
||||
'active': is_section_active,
|
||||
'graded': section.graded,
|
||||
}
|
||||
_add_timed_exam_info(user, course, section, section_context)
|
||||
|
||||
section_is_time_limited = (
|
||||
getattr(section, 'is_time_limited', False) and
|
||||
settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False)
|
||||
)
|
||||
if section_is_time_limited:
|
||||
# We need to import this here otherwise Lettuce test
|
||||
# harness fails. When running in 'harvest' mode, the
|
||||
# test service appears to get into trouble with
|
||||
# circular references (not sure which as edx_proctoring.api
|
||||
# doesn't import anything from edx-platform). Odd thing
|
||||
# is that running: manage.py lms runserver --settings=acceptance
|
||||
# works just fine, it's really a combination of Lettuce and the
|
||||
# 'harvest' management command
|
||||
#
|
||||
# One idea is that there is some coupling between
|
||||
# lettuce and the 'terrain' Djangoapps projects in /common
|
||||
# This would need more investigation
|
||||
from edx_proctoring.api import get_attempt_status_summary
|
||||
# update next and previous of active section, if applicable
|
||||
if is_section_active:
|
||||
if last_processed_section:
|
||||
previous_of_active_section = last_processed_section.copy()
|
||||
previous_of_active_section['chapter_url_name'] = last_processed_chapter.url_name
|
||||
elif found_active_section and not next_of_active_section:
|
||||
next_of_active_section = section_context.copy()
|
||||
next_of_active_section['chapter_url_name'] = chapter.url_name
|
||||
|
||||
#
|
||||
# call into edx_proctoring subsystem
|
||||
# to get relevant proctoring information regarding this
|
||||
# level of the courseware
|
||||
#
|
||||
# This will return None, if (user, course_id, content_id)
|
||||
# is not applicable
|
||||
#
|
||||
timed_exam_attempt_context = None
|
||||
try:
|
||||
timed_exam_attempt_context = get_attempt_status_summary(
|
||||
user.id,
|
||||
unicode(course.id),
|
||||
unicode(section.location)
|
||||
)
|
||||
except Exception, ex: # pylint: disable=broad-except
|
||||
# safety net in case something blows up in edx_proctoring
|
||||
# as this is just informational descriptions, it is better
|
||||
# to log and continue (which is safe) than to have it be an
|
||||
# unhandled exception
|
||||
log.exception(ex)
|
||||
sections.append(section_context)
|
||||
last_processed_section = section_context
|
||||
last_processed_chapter = chapter
|
||||
|
||||
if timed_exam_attempt_context:
|
||||
# yes, user has proctoring context about
|
||||
# this level of the courseware
|
||||
# so add to the accordion data context
|
||||
section_context.update({
|
||||
'proctoring': timed_exam_attempt_context,
|
||||
})
|
||||
|
||||
sections.append(section_context)
|
||||
toc_chapters.append({
|
||||
'display_name': chapter.display_name_with_default_escaped,
|
||||
'display_id': display_id,
|
||||
@@ -257,7 +221,61 @@ def toc_for_course(user, request, course, active_chapter, active_section, field_
|
||||
'sections': sections,
|
||||
'active': chapter.url_name == active_chapter
|
||||
})
|
||||
return toc_chapters
|
||||
return toc_chapters, previous_of_active_section, next_of_active_section
|
||||
|
||||
|
||||
def _add_timed_exam_info(user, course, section, section_context):
|
||||
"""
|
||||
Add in rendering context if exam is a timed exam (which includes proctored)
|
||||
"""
|
||||
section_is_time_limited = (
|
||||
getattr(section, 'is_time_limited', False) and
|
||||
settings.FEATURES.get('ENABLE_SPECIAL_EXAMS', False)
|
||||
)
|
||||
if section_is_time_limited:
|
||||
# We need to import this here otherwise Lettuce test
|
||||
# harness fails. When running in 'harvest' mode, the
|
||||
# test service appears to get into trouble with
|
||||
# circular references (not sure which as edx_proctoring.api
|
||||
# doesn't import anything from edx-platform). Odd thing
|
||||
# is that running: manage.py lms runserver --settings=acceptance
|
||||
# works just fine, it's really a combination of Lettuce and the
|
||||
# 'harvest' management command
|
||||
#
|
||||
# One idea is that there is some coupling between
|
||||
# lettuce and the 'terrain' Djangoapps projects in /common
|
||||
# This would need more investigation
|
||||
from edx_proctoring.api import get_attempt_status_summary
|
||||
|
||||
#
|
||||
# call into edx_proctoring subsystem
|
||||
# to get relevant proctoring information regarding this
|
||||
# level of the courseware
|
||||
#
|
||||
# This will return None, if (user, course_id, content_id)
|
||||
# is not applicable
|
||||
#
|
||||
timed_exam_attempt_context = None
|
||||
try:
|
||||
timed_exam_attempt_context = get_attempt_status_summary(
|
||||
user.id,
|
||||
unicode(course.id),
|
||||
unicode(section.location)
|
||||
)
|
||||
except Exception, ex: # pylint: disable=broad-except
|
||||
# safety net in case something blows up in edx_proctoring
|
||||
# as this is just informational descriptions, it is better
|
||||
# to log and continue (which is safe) than to have it be an
|
||||
# unhandled exception
|
||||
log.exception(ex)
|
||||
|
||||
if timed_exam_attempt_context:
|
||||
# yes, user has proctoring context about
|
||||
# this level of the courseware
|
||||
# so add to the accordion data context
|
||||
section_context.update({
|
||||
'proctoring': timed_exam_attempt_context,
|
||||
})
|
||||
|
||||
|
||||
def get_module(user, request, usage_key, field_data_cache,
|
||||
|
||||
Reference in New Issue
Block a user