From 7a4d89b1ad293c4b8387116397ca1484c9a4fe7b Mon Sep 17 00:00:00 2001 From: Chris Dodge Date: Fri, 28 Dec 2012 11:34:45 -0500 Subject: [PATCH] add in static asset link rewriting to the Course Handout section --- cms/djangoapps/contentstore/module_info_model.py | 10 +++++++--- cms/djangoapps/contentstore/views.py | 7 +++++-- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/cms/djangoapps/contentstore/module_info_model.py b/cms/djangoapps/contentstore/module_info_model.py index 2c77fcf313..0017010885 100644 --- a/cms/djangoapps/contentstore/module_info_model.py +++ b/cms/djangoapps/contentstore/module_info_model.py @@ -1,5 +1,5 @@ import logging - +from static_replace import replace_urls from xmodule.modulestore.exceptions import ItemNotFoundError from xmodule.modulestore import Location from xmodule.modulestore.django import modulestore @@ -7,7 +7,7 @@ from lxml import etree import re from django.http import HttpResponseBadRequest, Http404 -def get_module_info(store, location, parent_location = None): +def get_module_info(store, location, parent_location = None, rewrite_static_links = False): try: if location.revision is None: module = store.get_item(location) @@ -16,9 +16,13 @@ def get_module_info(store, location, parent_location = None): except ItemNotFoundError: raise Http404 + data = module.definition['data'] + if rewrite_static_links: + data = replace_urls(module.definition['data'], course_namespace = Location([module.location.tag, module.location.org, module.location.course, None, None])) + return { 'id': module.location.url(), - 'data': module.definition['data'], + 'data': data, 'metadata': module.metadata } diff --git a/cms/djangoapps/contentstore/views.py b/cms/djangoapps/contentstore/views.py index fb6a40eff3..8f10eadc4b 100644 --- a/cms/djangoapps/contentstore/views.py +++ b/cms/djangoapps/contentstore/views.py @@ -1009,14 +1009,17 @@ def module_info(request, module_location): if request.method == 'POST' and 'HTTP_X_HTTP_METHOD_OVERRIDE' in request.META: real_method = request.META['HTTP_X_HTTP_METHOD_OVERRIDE'] else: - real_method = request.method + real_method = request.method + + rewrite_static_links = request.GET.get('rewrite_url_links','True') in ['True', 'true'] + logging.debug('rewrite_static_links = {0} {1}'.format(request.GET.get('rewrite_url_links','False'), rewrite_static_links)) # check that logged in user has permissions to this item if not has_access(request.user, location): raise PermissionDenied() if real_method == 'GET': - return HttpResponse(json.dumps(get_module_info(get_modulestore(location), location)), mimetype="application/json") + return HttpResponse(json.dumps(get_module_info(get_modulestore(location), location, rewrite_static_links=rewrite_static_links)), mimetype="application/json") elif real_method == 'POST' or real_method == 'PUT': return HttpResponse(json.dumps(set_module_info(get_modulestore(location), location, request.POST)), mimetype="application/json") else: