Пример #1
0
    def _last_visited_module_path(self, request, course):
        """
        Returns the path from the last module visited by the current user in the given course up to
        the course module. If there is no such visit, the first item deep enough down the course
        tree is used.
        """
        field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
            course.id, request.user, course, depth=2)

        course_module = get_module_for_descriptor(request.user,
                                                  request,
                                                  course,
                                                  field_data_cache,
                                                  course.id,
                                                  course=course)

        path = [course_module]
        chapter = get_current_child(course_module, min_depth=2)
        if chapter is not None:
            path.append(chapter)
            section = get_current_child(chapter, min_depth=1)
            if section is not None:
                path.append(section)

        path.reverse()
        return path
Пример #2
0
def get_course_position(course_module):
    """
    Return the user's current place in the course.

    If this is the user's first time, leads to COURSE/CHAPTER/SECTION.
    If this isn't the users's first time, leads to COURSE/CHAPTER.

    If there is no current position in the course or chapter, then selects
    the first child.
    """
    urlargs = {'course_id': unicode(course_module.id)}
    chapter = get_current_child(course_module, min_depth=1)
    if chapter is None:
        log.debug("No chapter found when loading current position in course")
        return None

    urlargs['chapter'] = chapter.url_name
    if course_module.position is not None:
        return {
            'display_name': chapter.display_name_with_default_escaped,
            'url': reverse('courseware_chapter', kwargs=urlargs),
        }

    # Relying on default of returning first child
    section = get_current_child(chapter, min_depth=1)
    if section is None:
        log.debug("No section found when loading current position in course")
        return None

    urlargs['section'] = section.url_name
    return {
        'display_name': section.display_name_with_default_escaped,
        'url': reverse('courseware_section', kwargs=urlargs)
    }
Пример #3
0
def get_course_position(course_module):
    """
    Return the user's current place in the course.

    If this is the user's first time, leads to COURSE/CHAPTER/SECTION.
    If this isn't the users's first time, leads to COURSE/CHAPTER.

    If there is no current position in the course or chapter, then selects
    the first child.
    """
    urlargs = {'course_id': unicode(course_module.id)}
    chapter = get_current_child(course_module, min_depth=1)
    if chapter is None:
        log.debug("No chapter found when loading current position in course")
        return None

    urlargs['chapter'] = chapter.url_name
    if course_module.position is not None:
        return {
            'display_name': chapter.display_name_with_default_escaped,
            'url': reverse('courseware_chapter', kwargs=urlargs),
        }

    # Relying on default of returning first child
    section = get_current_child(chapter, min_depth=1)
    if section is None:
        log.debug("No section found when loading current position in course")
        return None

    urlargs['section'] = section.url_name
    return {
        'display_name': section.display_name_with_default_escaped,
        'url': reverse('courseware_section', kwargs=urlargs)
    }
Пример #4
0
 def test_get_current_child(self):
     self.assertIsNone(views.get_current_child(MagicMock()))
     mock_xmodule = MagicMock()
     mock_xmodule.position = -1
     mock_xmodule.get_display_items.return_value = ['one', 'two']
     self.assertEqual(views.get_current_child(mock_xmodule), 'one')
     mock_xmodule_2 = MagicMock()
     mock_xmodule_2.position = 3
     mock_xmodule_2.get_display_items.return_value = []
     self.assertIsNone(views.get_current_child(mock_xmodule_2))
Пример #5
0
 def test_get_current_child(self):
     self.assertIsNone(views.get_current_child(MagicMock()))
     mock_xmodule = MagicMock()
     mock_xmodule.position = -1
     mock_xmodule.get_display_items.return_value = ['one', 'two']
     self.assertEqual(views.get_current_child(mock_xmodule), 'one')
     mock_xmodule_2 = MagicMock()
     mock_xmodule_2.position = 3
     mock_xmodule_2.get_display_items.return_value = []
     self.assertIsNone(views.get_current_child(mock_xmodule_2))
Пример #6
0
    def _last_visited_module_path(self, request, course):
        """
        Returns the path from the last module visited by the current user in the given course up to
        the course module. If there is no such visit, the first item deep enough down the course
        tree is used.
        """
        field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
            course.id, request.user, course, depth=2)

        course_module = get_module_for_descriptor(request.user, request, course, field_data_cache, course.id)

        path = [course_module]
        chapter = get_current_child(course_module, min_depth=2)
        if chapter is not None:
            path.append(chapter)
            section = get_current_child(chapter, min_depth=1)
            if section is not None:
                path.append(section)

        path.reverse()
        return path
Пример #7
0
    def _last_visited_module_id(self, request, course):
        """
        Returns the id of the last module visited by the current user in the given course.
        If there is no such visit returns the default (the first item deep enough down the course tree)
        """
        field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
            course.id, request.user, course, depth=2)

        course_module = get_module_for_descriptor(request.user, request, course, field_data_cache, course.id)
        current = course_module

        child = current
        while child:
            child = get_current_child(current)
            if child:
                current = child

        return current
Пример #8
0
    def _last_visited_module_path(self, request, course):
        """
        Returns the path from the last module visited by the current user in the given course up to
        the course module. If there is no such visit, the first item deep enough down the course
        tree is used.
        """
        field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
            course.id, request.user, course, depth=2)

        course_module = get_module_for_descriptor(request.user, request, course, field_data_cache, course.id)
        current = course_module

        path = []
        child = current
        while child:
            path.append(child)
            child = get_current_child(current)
            if child:
                current = child

        path.reverse()
        return path