Commit 6ed2737c by Chris Dodge

make LMS forum subsystem more robust in case of orphaned discussion modules.…

make LMS forum subsystem more robust in case of orphaned discussion modules. Given our draft/non-draft duality, we don't currently have a means to always do proper housekeeping at this point in time. However, we have to stop the LMS Forums from blowing up when encoutering one of these.
parent b68aff72
...@@ -11,6 +11,8 @@ from django.http import HttpResponse ...@@ -11,6 +11,8 @@ from django.http import HttpResponse
from django.utils import simplejson from django.utils import simplejson
from django_comment_client.models import Role from django_comment_client.models import Role
from django_comment_client.permissions import check_permissions_by_view from django_comment_client.permissions import check_permissions_by_view
from xmodule.modulestore.exceptions import NoPathToItem
from mitxmako import middleware from mitxmako import middleware
import pystache_custom as pystache import pystache_custom as pystache
...@@ -158,6 +160,14 @@ def initialize_discussion_info(course): ...@@ -158,6 +160,14 @@ def initialize_discussion_info(course):
log.warning("Required key '%s' not in discussion %s, leaving out of category map" % (key, module.location)) log.warning("Required key '%s' not in discussion %s, leaving out of category map" % (key, module.location))
skip_module = True skip_module = True
# cdodge: pre-compute the path_to_location. Note this can throw an exception for any
# dangling discussion modules
try:
_DISCUSSIONINFO[course.id]['path_to_location'] = path_to_location(modulestore(), course.id, module.location)
except NoPathToItem:
log.warning("Could not compute path_to_location for {0}. Perhaps this is an orphaned discussion module?!? Skipping...".format(module.location))
skip_module = True
if skip_module: if skip_module:
continue continue
...@@ -360,7 +370,13 @@ def get_courseware_context(content, course): ...@@ -360,7 +370,13 @@ def get_courseware_context(content, course):
if id in id_map: if id in id_map:
location = id_map[id]["location"].url() location = id_map[id]["location"].url()
title = id_map[id]["title"] title = id_map[id]["title"]
(course_id, chapter, section, position) = path_to_location(modulestore(), course.id, location)
# cdodge: did we pre-compute, if so, then let's use that rather than recomputing
if 'path_to_location' in _DISCUSSIONINFO[course.id]:
(course_id, chapter, section, position) = _DISCUSSIONINFO[course.id]['path_to_location']
else:
(course_id, chapter, section, position) = path_to_location(modulestore(), course.id, location)
url = reverse('courseware_position', kwargs={"course_id":course_id, url = reverse('courseware_position', kwargs={"course_id":course_id,
"chapter":chapter, "chapter":chapter,
"section":section, "section":section,
......
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