Commit e2e52445 by Victor Shnayder

Make courseware index view more bulletproof

parent c0cdff70
...@@ -184,34 +184,54 @@ def index(request, course_id, chapter=None, section=None, ...@@ -184,34 +184,54 @@ def index(request, course_id, chapter=None, section=None,
chapter = clean(chapter) chapter = clean(chapter)
section = clean(section) section = clean(section)
context = { try:
'csrf': csrf(request)['csrf_token'], context = {
'accordion': render_accordion(request, course, chapter, section), 'csrf': csrf(request)['csrf_token'],
'COURSE_TITLE': course.title, 'accordion': render_accordion(request, course, chapter, section),
'course': course, 'COURSE_TITLE': course.title,
'init': '', 'course': course,
'content': '' 'init': '',
} 'content': ''
}
look_for_module = chapter is not None and section is not None
if look_for_module: look_for_module = chapter is not None and section is not None
# TODO (cpennington): Pass the right course in here if look_for_module:
# TODO (cpennington): Pass the right course in here
section_descriptor = get_section(course, chapter, section)
if section_descriptor is not None: section_descriptor = get_section(course, chapter, section)
student_module_cache = StudentModuleCache(request.user, if section_descriptor is not None:
section_descriptor) student_module_cache = StudentModuleCache(request.user,
module, _, _, _ = get_module(request.user, request, section_descriptor)
section_descriptor.location, module, _, _, _ = get_module(request.user, request,
student_module_cache) section_descriptor.location,
context['content'] = module.get_html() student_module_cache)
context['content'] = module.get_html()
else:
log.warning("Couldn't find a section descriptor for course_id '{0}',"
"chapter '{1}', section '{2}'".format(
course_id, chapter, section))
result = render_to_response('courseware.html', context)
except:
# In production, don't want to let a 500 out for any reason
if settings.DEBUG:
raise
else: else:
log.warning("Couldn't find a section descriptor for course_id '{0}'," log.exception("Error in index view: user={user}, course={course},"
"chapter '{1}', section '{2}'".format( " chapter={chapter} section={section}"
course_id, chapter, section)) "position={position}".format(
user=request.user,
course=course,
chapter=chapter,
section=section,
position=position
))
try:
result = render_to_response('courseware-error.html', {})
except:
result = HttpResponse("There was an unrecoverable error")
result = render_to_response('courseware.html', context)
return result return result
@ensure_csrf_cookie @ensure_csrf_cookie
......
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