Commit 054aa95b by Andy Armstrong

Allow non-public XBlock assets in debug mode

parent d4f2fe12
......@@ -711,6 +711,9 @@ INSTALLED_APPS = (
'south',
'method_override',
# Common views
'openedx.core.djangoapps.common_views',
# History tables
'simple_history',
......
......@@ -32,7 +32,7 @@ urlpatterns = patterns(
'contentstore.views.component_handler', name='component_handler'),
url(r'^xblock/resource/(?P<block_type>[^/]*)/(?P<uri>.*)$',
'contentstore.views.xblock.xblock_resource', name='xblock_resource_url'),
'openedx.core.djangoapps.common_views.xblock.xblock_resource', name='xblock_resource_url'),
# temporary landing page for a course
url(r'^edge/(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<coursename>[^/]+)$',
......
......@@ -5,7 +5,6 @@ Module rendering
import hashlib
import json
import logging
import mimetypes
import static_replace
......@@ -946,23 +945,6 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None):
return _invoke_xblock_handler(request, course_id, usage_id, handler, suffix, course=course)
def xblock_resource(request, block_type, uri): # pylint: disable=unused-argument
"""
Return a package resource for the specified XBlock.
"""
try:
xblock_class = XBlock.load_class(block_type, select=settings.XBLOCK_SELECT_FUNCTION)
content = xblock_class.open_local_resource(uri)
except IOError:
log.info('Failed to load xblock resource', exc_info=True)
raise Http404
except Exception: # pylint: disable=broad-except
log.error('Failed to load xblock resource', exc_info=True)
raise Http404
mimetype, _ = mimetypes.guess_type(uri)
return HttpResponse(content, mimetype=mimetype)
def get_module_by_usage_id(request, course_id, usage_id, disable_staff_debug_info=False, course=None):
"""
Gets a module instance based on its `usage_id` in a course, for a given request/user
......
......@@ -1794,6 +1794,9 @@ INSTALLED_APPS = (
'djcelery',
'south',
# Common views
'openedx.core.djangoapps.common_views',
# History tables
'simple_history',
......
......@@ -307,7 +307,7 @@ if settings.COURSEWARE_ENABLED:
# xblock Resource URL
url(
r'xblock/resource/(?P<block_type>[^/]+)/(?P<uri>.*)$',
'courseware.module_render.xblock_resource',
'openedx.core.djangoapps.common_views.xblock.xblock_resource',
name='xblock_resource_url',
),
......
"""
Views dedicated to rendering xblocks.
Common views dedicated to rendering xblocks.
"""
from __future__ import absolute_import
import logging
import mimetypes
import pkg_resources
from xblock.core import XBlock
......@@ -21,7 +22,13 @@ def xblock_resource(request, block_type, uri): # pylint: disable=unused-argumen
"""
try:
xblock_class = XBlock.load_class(block_type, select=settings.XBLOCK_SELECT_FUNCTION)
content = xblock_class.open_local_resource(uri)
# Note: in debug mode, return any file rather than going through the XBlock which
# will only return public files. This allows unbundled files to be served up
# during development.
if settings.DEBUG:
content = pkg_resources.resource_stream(xblock_class.__module__, uri)
else:
content = xblock_class.open_local_resource(uri)
except IOError:
log.info('Failed to load xblock resource', exc_info=True)
raise Http404
......
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