Example #1
0
    def test_task_invocation(self):
        """Test outline auto-creation after course publish"""
        course_key = CourseKey.from_string("course-v1:TNL+7733+2021-01-21")
        with self.assertRaises(CourseOutlineData.DoesNotExist):
            get_course_outline(course_key)

        course = CourseFactory.create(
            org=course_key.org,
            course=course_key.course,
            run=course_key.run,
            default_store=ModuleStoreEnum.Type.split,
        )
        section = ItemFactory.create(parent_location=course.location,
                                     category="chapter",
                                     display_name="First Section")
        ItemFactory.create(parent_location=section.location,
                           category="sequential",
                           display_name="First Sequence")
        ItemFactory.create(parent_location=section.location,
                           category="sequential",
                           display_name="Second Sequence")
        self.store.publish(course.location, self.user.id)

        outline = get_course_outline(course_key)
        assert len(outline.sections) == 1
        assert len(outline.sequences) == 2
def get_due_dates(request, course_key, user):
    """
    Get due date information for a user for blocks in a course.

    Arguments:
        request: the request object
        course_key (CourseKey): the CourseKey for the course
        user: the user object for which we want due date information

    Returns:
        due_dates (list): a list of dictionaries containing due date information
            keys:
                name: the display name of the block
                url: the deep link to the block
                date: the due date for the block
    """
    try:
        outline = get_course_outline(course_key)
    except (ValueError, CourseOutlineData.DoesNotExist):
        # Either this course is Old Mongo-backed or doesn't have a generated course outline.
        course_version = None
    else:
        course_version = outline.published_version

    dates = get_dates_for_course(course_key,
                                 user,
                                 published_version=course_version)

    store = modulestore()

    due_dates = []
    for (block_key, date_type), date in dates.items():
        if date_type == 'due':
            try:
                block_display_name = store.get_item(block_key).display_name
            except ItemNotFoundError:
                logger.exception(
                    f'Failed to get block for due date item with key: {block_key}'
                )
                block_display_name = UNKNOWN_BLOCK_DISPLAY_NAME

            # get url to the block in the course
            block_url = reverse('jump_to', args=[course_key, block_key])
            block_url = request.build_absolute_uri(block_url)

            due_dates.append({
                'name': block_display_name,
                'url': block_url,
                'date': date,
            })
    return due_dates