Ejemplo n.º 1
0
    def get_ordered_updates(self, request, course):
        """
        Returns any course updates in reverse chronological order.
        """
        info_module = get_course_info_section_module(request, request.user, course, 'updates')

        updates = info_module.items if info_module else []
        info_block = getattr(info_module, '_xmodule', info_module) if info_module else None
        ordered_updates = [update for update in updates if update.get('status') == self.STATUS_VISIBLE]
        ordered_updates.sort(
            key=lambda item: (self.safe_parse_date(item['date']), item['id']),
            reverse=True
        )
        keyword_context = {
            'username': request.user.username,
            'user_id': request.user.id,
            'name': request.user.profile.name,
            'course_title': course.display_name,
            'course_id': course.id,
            'course_start_date': get_default_time_display(course.start),
            'course_end_date': get_default_time_display(course.end),
        }
        for update in ordered_updates:
            update['content'] = info_block.system.replace_urls(update['content'])
            update['content'] = info_block.system.substitute_keywords_with_data(update['content'], keyword_context)
        return ordered_updates
Ejemplo n.º 2
0
    def get_ordered_updates(self, request, course):
        """
        Returns any course updates in reverse chronological order.
        """
        info_module = get_course_info_section_module(request, request.user,
                                                     course, 'updates')

        updates = info_module.items if info_module else []
        info_block = getattr(info_module, '_xmodule',
                             info_module) if info_module else None
        ordered_updates = [
            update for update in updates
            if update.get('status') == self.STATUS_VISIBLE
        ]
        ordered_updates.sort(key=lambda item:
                             (self.safe_parse_date(item['date']), item['id']),
                             reverse=True)
        keyword_context = {
            'username': request.user.username,
            'user_id': request.user.id,
            'name': request.user.profile.name,
            'course_title': course.display_name,
            'course_id': course.id,
            'course_start_date': get_default_time_display(course.start),
            'course_end_date': get_default_time_display(course.end),
        }
        for update in ordered_updates:
            update['content'] = info_block.system.replace_urls(
                update['content'])
            update[
                'content'] = info_block.system.substitute_keywords_with_data(
                    update['content'], keyword_context)
        return ordered_updates
Ejemplo n.º 3
0
    def render_to_fragment(self, request, course_id=None, **kwargs):
        """
        Renders the course's home page as a fragment.
        """
        course_key = CourseKey.from_string(course_id)
        course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
        course_url_name = default_course_url_name(request)
        course_url = reverse(course_url_name, kwargs={'course_id': unicode(course.id)})

        # Fetch all of the updates individually
        info_module = get_course_info_section_module(request, request.user, course, 'updates')
        ordered_updates = self.order_updates(info_module.items)

        # Older implementations and a few tests store a single html object representing all the updates
        plain_html_updates = info_module.data

        # Render the course home fragment
        context = {
            'csrf': csrf(request)['csrf_token'],
            'course': course,
            'course_url': course_url,
            'updates': ordered_updates,
            'plain_html_updates': plain_html_updates,
            'disable_courseware_js': True,
            'uses_pattern_library': True,
        }
        html = render_to_string('course_experience/course-updates-fragment.html', context)
        return Fragment(html)
Ejemplo n.º 4
0
 def get_plain_html_updates(self, request, course):
     """
     Returns any course updates in an html chunk. Used
     for older implementations and a few tests that store
     a single html object representing all the updates.
     """
     info_module = get_course_info_section_module(request, request.user, course, 'updates')
     info_block = getattr(info_module, '_xmodule', info_module)
     return info_block.system.replace_urls(info_module.data) if info_module else ''
Ejemplo n.º 5
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')
     updates_to_show = [
         update for update in reversed(getattr(course_updates_module, 'items', []))
         if update.get("status") != "deleted"
     ]
     return Response(updates_to_show)
Ejemplo n.º 6
0
 def get_plain_html_updates(self, request, course):
     """
     Returns any course updates in an html chunk. Used
     for older implementations and a few tests that store
     a single html object representing all the updates.
     """
     info_module = get_course_info_section_module(request, request.user, course, 'updates')
     info_block = getattr(info_module, '_xmodule', info_module)
     return info_block.system.replace_urls(info_module.data) if info_module else ''
Ejemplo n.º 7
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:
         return Response({'handouts_html': course_handouts_module.data})
     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)))
Ejemplo n.º 8
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 = apply_wrappers_to_content(course_handouts_module.data, course_handouts_module, request)
         return Response({'handouts_html': handouts_html})
     else:
         # course_handouts_module could be None if there are no handouts
         return Response({'handouts_html': None})
Ejemplo n.º 9
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 = apply_wrappers_to_content(course_handouts_module.data, course_handouts_module, request)
         return Response({'handouts_html': handouts_html})
     else:
         # course_handouts_module could be None if there are no handouts
         return Response({'handouts_html': None})
Ejemplo n.º 10
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')
     updates_to_show = [
         update
         for update in reversed(getattr(course_updates_module, 'items', []))
         if update.get("status") != "deleted"
     ]
     return Response(updates_to_show)
Ejemplo n.º 11
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:
         return Response({'handouts_html': course_handouts_module.data})
     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)))
Ejemplo n.º 12
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)))
Ejemplo n.º 13
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)
Ejemplo n.º 14
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:
            item['content'] = apply_wrappers_to_content(item['content'], course_updates_module, request)

        return Response(updates_to_show)
Ejemplo n.º 15
0
    def welcome_message_html(cls, request, course):
        """
        Returns the course's welcome message or None if it doesn't have one.
        """
        info_module = get_course_info_section_module(request, request.user,
                                                     course, 'updates')
        if not info_module:
            return None

        # Return the course update with the most recent publish date
        info_block = getattr(info_module, '_xmodule', info_module)
        ordered_updates = info_block.ordered_updates()
        return ordered_updates[0]['content'] if ordered_updates else None
Ejemplo n.º 16
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:
            item['content'] = apply_wrappers_to_content(item['content'], course_updates_module, request)

        return Response(updates_to_show)
Ejemplo n.º 17
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)))
Ejemplo n.º 18
0
    def welcome_message_html(cls, request, course):
        """
        Returns the course's welcome message or None if it doesn't have one.
        """
        info_module = get_course_info_section_module(request, request.user, course, 'updates')
        if not info_module:
            return None

        # Return the course update with the most recent publish date
        ordered_updates = CourseUpdatesFragmentView.order_updates(info_module.items)
        content = None
        if ordered_updates:
            info_block = getattr(info_module, '_xmodule', info_module)
            content = info_block.system.replace_urls(ordered_updates[0]['content'])

        return content
Ejemplo n.º 19
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)))
Ejemplo n.º 20
0
def get_ordered_updates(request, course):
    """
    Returns any course updates in reverse chronological order.
    """
    info_module = get_course_info_section_module(request, request.user, course, 'updates')

    updates = info_module.items if info_module else []
    info_block = getattr(info_module, '_xmodule', info_module) if info_module else None
    ordered_updates = [update for update in updates if update.get('status') == STATUS_VISIBLE]
    ordered_updates.sort(
        key=lambda item: (safe_parse_date(item['date']), item['id']),
        reverse=True
    )
    for update in ordered_updates:
        update['content'] = info_block.system.replace_urls(update['content'])
    return ordered_updates
Ejemplo n.º 21
0
def get_ordered_updates(request, course):
    """
    Returns any course updates in reverse chronological order.
    """
    info_module = get_course_info_section_module(request, request.user, course, 'updates')

    updates = info_module.items if info_module else []
    info_block = getattr(info_module, '_xmodule', info_module) if info_module else None
    ordered_updates = [update for update in updates if update.get('status') == STATUS_VISIBLE]
    ordered_updates.sort(
        key=lambda item: (safe_parse_date(item['date']), item['id']),
        reverse=True
    )
    for update in ordered_updates:
        update['content'] = info_block.system.replace_urls(update['content'])
    return ordered_updates
Ejemplo n.º 22
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})
Ejemplo n.º 23
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)))
Ejemplo n.º 24
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)
Ejemplo n.º 25
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)
Ejemplo n.º 26
0
 def get_plain_html_updates(self, request, course):
     """
     Returns any course updates in an html chunk. Used
     for older implementations and a few tests that store
     a single html object representing all the updates.
     """
     info_module = get_course_info_section_module(request, request.user, course, 'updates')
     info_block = getattr(info_module, '_xmodule', info_module)
     update_content = info_block.system.replace_urls(info_module.data) if info_module else ''
     keyword_context = {
         'username': request.user.username,
         'user_id': request.user.id,
         'name': request.user.profile.name,
         'course_title': course.display_name,
         'course_id': course.id,
         'course_start_date': get_default_time_display(course.start),
         'course_end_date': get_default_time_display(course.end),
     }
     update_content = info_block.system.substitute_keywords_with_data(update_content, keyword_context)
     return update_content
Ejemplo n.º 27
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)
Ejemplo n.º 28
0
 def get_plain_html_updates(self, request, course):
     """
     Returns any course updates in an html chunk. Used
     for older implementations and a few tests that store
     a single html object representing all the updates.
     """
     info_module = get_course_info_section_module(request, request.user,
                                                  course, 'updates')
     info_block = getattr(info_module, '_xmodule', info_module)
     update_content = info_block.system.replace_urls(
         info_module.data) if info_module else ''
     keyword_context = {
         'username': request.user.username,
         'user_id': request.user.id,
         'name': request.user.profile.name,
         'course_title': course.display_name,
         'course_id': course.id,
         'course_start_date': get_default_time_display(course.start),
         'course_end_date': get_default_time_display(course.end),
     }
     update_content = info_block.system.substitute_keywords_with_data(
         update_content, keyword_context)
     return update_content