def get(self, request, course, *args, **kwargs): # There are other fields, but they don't seem to be in use. # see courses.py:get_course_about_section. # # This can also return None, so check for that before calling strip() about_section_html = get_course_about_section(course, "overview") about_section_html = make_static_urls_absolute(self.request, about_section_html) return Response( {"overview": about_section_html.strip() if about_section_html else ""} )
def list(self, request, course, *args, **kwargs): course_handouts_module = get_course_info_section_module(request, request.user, course, "handouts") if course_handouts_module: handouts_html = course_handouts_module.data handouts_html = replace_static_urls( handouts_html, course_id=course.id, static_asset_path=course.static_asset_path ) handouts_html = make_static_urls_absolute(self.request, handouts_html) return Response({"handouts_html": handouts_html}) else: # course_handouts_module could be None if there are no handouts raise Http404(u"No handouts for {}".format(unicode(course.id)))
def list(self, request, course, *args, **kwargs): course_updates_module = get_course_info_section_module(request, request.user, course, "updates") update_items = get_course_update_items(course_updates_module) updates_to_show = [update for update in update_items if update.get("status") != "deleted"] for item in updates_to_show: content = item["content"] content = replace_static_urls(content, course_id=course.id, static_asset_path=course.static_asset_path) item["content"] = make_static_urls_absolute(request, content) return Response(updates_to_show)
def get(self, request, course, *args, **kwargs): # There are other fields, but they don't seem to be in use. # see courses.py:get_course_about_section. # # This can also return None, so check for that before calling strip() about_section_html = get_course_about_section(course, "overview") about_section_html = make_static_urls_absolute(self.request, about_section_html) return Response({ "overview": about_section_html.strip() if about_section_html else "" })
def list(self, request, course, *args, **kwargs): course_handouts_module = get_course_info_section_module(request, course, 'handouts') if course_handouts_module: handouts_html = course_handouts_module.data handouts_html = replace_static_urls( handouts_html, course_id=course.id, static_asset_path=course.static_asset_path) handouts_html = make_static_urls_absolute(self.request, handouts_html) return Response({'handouts_html': handouts_html}) else: # course_handouts_module could be None if there are no handouts raise Http404(u"No handouts for {}".format(unicode(course.id)))
def list(self, request, *args, **kwargs): course_id = CourseKey.from_string(kwargs['course_id']) course = modulestore().get_course(course_id) course_handouts_module = get_course_info_section_module(request, course, 'handouts') if course_handouts_module: handouts_html = course_handouts_module.data handouts_html = replace_static_urls( handouts_html, course_id=course_id, static_asset_path=course.static_asset_path) handouts_html = make_static_urls_absolute(self.request, handouts_html) return Response({'handouts_html': handouts_html}) else: # course_handouts_module could be None if there are no handouts # (such as while running tests) raise Http404(u"No handouts for {}".format(unicode(course_id)))
def list(self, request, course, *args, **kwargs): course_handouts_module = get_course_info_section_module(request, request.user, course, 'handouts') if course_handouts_module: if course_handouts_module.data == "<ol></ol>": handouts_html = None else: handouts_html = course_handouts_module.data handouts_html = replace_static_urls( handouts_html, course_id=course.id, static_asset_path=course.static_asset_path ) handouts_html = make_static_urls_absolute(self.request, handouts_html) return Response({'handouts_html': handouts_html}) else: # course_handouts_module could be None if there are no handouts return Response({'handouts_html': None})
def list(self, request, course, *args, **kwargs): course_updates_module = get_course_info_section_module(request, course, 'updates') update_items = get_course_update_items(course_updates_module) updates_to_show = [ update for update in update_items if update.get("status") != "deleted" ] for item in updates_to_show: content = item['content'] content = replace_static_urls( content, course_id=course.id, static_asset_path=course.static_asset_path) item['content'] = make_static_urls_absolute(request, content) return Response(updates_to_show)
def list(self, request, course, *args, **kwargs): course_updates_module = get_course_info_section_module(request, course, 'updates') update_items = reversed(getattr(course_updates_module, 'items', [])) updates_to_show = [ update for update in update_items if update.get("status") != "deleted" ] for item in updates_to_show: content = item['content'] content = replace_static_urls( content, course_id=course.id, static_asset_path=course.static_asset_path) item['content'] = make_static_urls_absolute(request, content) return Response(updates_to_show)
def list(self, request, *args, **kwargs): course_id = CourseKey.from_string(kwargs['course_id']) course = modulestore().get_course(course_id) course_handouts_module = get_course_info_section_module( request, course, 'handouts') if course_handouts_module: handouts_html = course_handouts_module.data handouts_html = replace_static_urls( handouts_html, course_id=course_id, static_asset_path=course.static_asset_path) handouts_html = make_static_urls_absolute(self.request, handouts_html) return Response({'handouts_html': handouts_html}) else: # course_handouts_module could be None if there are no handouts # (such as while running tests) raise Http404(u"No handouts for {}".format(unicode(course_id)))
def list(self, request, *args, **kwargs): course_id = CourseKey.from_string(kwargs['course_id']) course = modulestore().get_course(course_id) course_updates_module = get_course_info_section_module( request, course, 'updates') update_items = reversed(getattr(course_updates_module, 'items', [])) updates_to_show = [ update for update in update_items if update.get("status") != "deleted" ] for item in updates_to_show: content = item['content'] content = replace_static_urls( content, course_id=course_id, static_asset_path=course.static_asset_path) item['content'] = make_static_urls_absolute(request, content) return Response(updates_to_show)
def apply_wrappers_to_content(content, module, request): """ Updates a piece of html content with the filter functions stored in its module system, then replaces any static urls with absolute urls. Args: content: The html content to which to apply the content wrappers generated for this module system. module: The module containing a reference to the module system which contains functions to apply to the content. These functions include: * Replacing static url's * Replacing course url's * Replacing jump to id url's request: The request, used to replace static URLs with absolute URLs. Returns: A piece of html content containing the original content updated by each wrapper. """ content = module.system.replace_urls(content) content = module.system.replace_course_urls(content) content = module.system.replace_jump_to_id_urls(content) return make_static_urls_absolute(request, content)
def test_static_urls(mock_request): mock_request.build_absolute_uri = lambda url: 'http://' + url result = make_static_urls_absolute(mock_request, STATIC_SOURCE) assert_equals(result, '\"http:///static/file.png\"')