Commit d05b7a21 by Andy Armstrong

Merge pull request #10312 from edx/andya/dev-xblock-assets

Allow non-public XBlock assets in debug mode
parents 9cfbbb23 054aa95b
...@@ -711,6 +711,9 @@ INSTALLED_APPS = ( ...@@ -711,6 +711,9 @@ INSTALLED_APPS = (
'south', 'south',
'method_override', 'method_override',
# Common views
'openedx.core.djangoapps.common_views',
# History tables # History tables
'simple_history', 'simple_history',
......
...@@ -32,7 +32,7 @@ urlpatterns = patterns( ...@@ -32,7 +32,7 @@ urlpatterns = patterns(
'contentstore.views.component_handler', name='component_handler'), 'contentstore.views.component_handler', name='component_handler'),
url(r'^xblock/resource/(?P<block_type>[^/]*)/(?P<uri>.*)$', 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 # temporary landing page for a course
url(r'^edge/(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<coursename>[^/]+)$', url(r'^edge/(?P<org>[^/]+)/(?P<course>[^/]+)/course/(?P<coursename>[^/]+)$',
......
...@@ -5,7 +5,6 @@ Module rendering ...@@ -5,7 +5,6 @@ Module rendering
import hashlib import hashlib
import json import json
import logging import logging
import mimetypes
import static_replace import static_replace
...@@ -946,23 +945,6 @@ def handle_xblock_callback(request, course_id, usage_id, handler, suffix=None): ...@@ -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) 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): 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 Gets a module instance based on its `usage_id` in a course, for a given request/user
......
...@@ -1794,6 +1794,9 @@ INSTALLED_APPS = ( ...@@ -1794,6 +1794,9 @@ INSTALLED_APPS = (
'djcelery', 'djcelery',
'south', 'south',
# Common views
'openedx.core.djangoapps.common_views',
# History tables # History tables
'simple_history', 'simple_history',
......
...@@ -307,7 +307,7 @@ if settings.COURSEWARE_ENABLED: ...@@ -307,7 +307,7 @@ if settings.COURSEWARE_ENABLED:
# xblock Resource URL # xblock Resource URL
url( url(
r'xblock/resource/(?P<block_type>[^/]+)/(?P<uri>.*)$', 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', name='xblock_resource_url',
), ),
......
""" """
Views dedicated to rendering xblocks. Common views dedicated to rendering xblocks.
""" """
from __future__ import absolute_import from __future__ import absolute_import
import logging import logging
import mimetypes import mimetypes
import pkg_resources
from xblock.core import XBlock from xblock.core import XBlock
...@@ -21,6 +22,12 @@ def xblock_resource(request, block_type, uri): # pylint: disable=unused-argumen ...@@ -21,6 +22,12 @@ def xblock_resource(request, block_type, uri): # pylint: disable=unused-argumen
""" """
try: try:
xblock_class = XBlock.load_class(block_type, select=settings.XBLOCK_SELECT_FUNCTION) xblock_class = XBlock.load_class(block_type, select=settings.XBLOCK_SELECT_FUNCTION)
# 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) content = xblock_class.open_local_resource(uri)
except IOError: except IOError:
log.info('Failed to load xblock resource', exc_info=True) log.info('Failed to load xblock resource', exc_info=True)
......
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