コード例 #1
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)
    }
コード例 #2
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
コード例 #3
0
ファイル: views.py プロジェクト: Lektorium-LLC/edx-platform
    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
コード例 #4
0
    def test_get_current_child(self):
        mock_xmodule = mock.MagicMock()
        self.assertIsNone(get_current_child(mock_xmodule))

        mock_xmodule.position = -1
        mock_xmodule.get_display_items.return_value = ['one', 'two', 'three']
        self.assertEqual(get_current_child(mock_xmodule), 'one')

        mock_xmodule.position = 2
        self.assertEqual(get_current_child(mock_xmodule), 'two')
        self.assertEqual(get_current_child(mock_xmodule, requested_child='first'), 'one')
        self.assertEqual(get_current_child(mock_xmodule, requested_child='last'), 'three')

        mock_xmodule.position = 3
        mock_xmodule.get_display_items.return_value = []
        self.assertIsNone(get_current_child(mock_xmodule))
コード例 #5
0
    def test_get_current_child(self):
        mock_xmodule = mock.MagicMock()
        self.assertIsNone(get_current_child(mock_xmodule))

        mock_xmodule.position = -1
        mock_xmodule.get_display_items.return_value = ['one', 'two', 'three']
        self.assertEqual(get_current_child(mock_xmodule), 'one')

        mock_xmodule.position = 2
        self.assertEqual(get_current_child(mock_xmodule), 'two')
        self.assertEqual(get_current_child(mock_xmodule, requested_child='first'), 'one')
        self.assertEqual(get_current_child(mock_xmodule, requested_child='last'), 'three')

        mock_xmodule.position = 3
        mock_xmodule.get_display_items.return_value = []
        self.assertIsNone(get_current_child(mock_xmodule))
コード例 #6
0
 def _find_block(self, parent, url_name, block_type, min_depth=None):
     """
     Finds the block in the parent with the specified url_name.
     If not found, calls get_current_child on the parent.
     """
     child = None
     if url_name:
         child = parent.get_child_by(lambda m: m.location.name == url_name)
         if not child:
             # User may be trying to access a child that isn't live yet
             if not self._is_masquerading_as_student():
                 raise Http404(
                     'No {block_type} found with name {url_name}'.format(
                         block_type=block_type,
                         url_name=url_name,
                     ))
         elif min_depth and not child.has_children_at_depth(min_depth - 1):
             child = None
     if not child:
         child = get_current_child(
             parent,
             min_depth=min_depth,
             requested_child=self.request.GET.get("child"))
     return child