This commit is contained in:
Chris Dodge
2013-07-25 00:50:42 -04:00
parent 2616d8f7a2
commit cff93d324b
12 changed files with 53 additions and 19 deletions

View File

@@ -6,11 +6,14 @@ from xmodule.modulestore import InvalidLocationError
from cache_toolbox.core import get_cached_content, set_cached_content
from xmodule.exceptions import NotFoundError
import logging
class StaticContentServer(object):
def process_request(self, request):
# look to see if the request is prefixed with 'c4x' tag
if request.path.startswith('/' + XASSET_LOCATION_TAG + '/'):
logging.debug('**** path = {0}'.format(request.path))
try:
loc = StaticContent.get_location_from_path(request.path)
except InvalidLocationError:
@@ -24,8 +27,10 @@ class StaticContentServer(object):
if content is None:
# nope, not in cache, let's fetch from DB
try:
logging.debug('!!!! loc = {0}'.format(loc))
content = contentstore().find(loc, as_stream=True)
except NotFoundError:
logging.debug('**** NOT FOUND')
response = HttpResponse()
response.status_code = 404
return response

View File

@@ -124,7 +124,7 @@ def replace_static_urls(text, data_directory, course_id=None):
else:
# if not, then assume it's courseware specific content and then look in the
# Mongo-backed database
url = StaticContent.convert_legacy_static_url(rest, course_id)
url = StaticContent.convert_legacy_static_url_with_course_id(rest, course_id)
# Otherwise, look the file up in staticfiles_storage, and append the data directory if needed
else:
course_path = "/".join((data_directory, rest))

View File

@@ -95,6 +95,7 @@ def index(request, extra_context={}, user=None):
courses = sort_by_announcement(courses)
context = {'courses': courses}
context.update(extra_context)
return render_to_response('index.html', context)

View File

@@ -76,7 +76,7 @@ def replace_course_urls(get_html, course_id):
return _get_html
def replace_static_urls(get_html, data_dir, course_namespace=None):
def replace_static_urls(get_html, data_dir, course_id=None):
"""
Updates the supplied module with a new get_html function that wraps
the old get_html function and substitutes urls of the form /static/...
@@ -85,7 +85,7 @@ def replace_static_urls(get_html, data_dir, course_namespace=None):
@wraps(get_html)
def _get_html():
return static_replace.replace_static_urls(get_html(), data_dir, course_namespace)
return static_replace.replace_static_urls(get_html(), data_dir, course_id)
return _get_html