Beispiel #1
0
    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 ""}
        )
Beispiel #2
0
 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)))
Beispiel #3
0
    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)
Beispiel #4
0
    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 ""
        })
Beispiel #5
0
 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)))
Beispiel #6
0
 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)))
Beispiel #7
0
 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})
Beispiel #8
0
    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)
Beispiel #9
0
    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)
Beispiel #10
0
 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)))
Beispiel #11
0
    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)
Beispiel #13
0
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\"')
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\"')