def get_outline_from_modulestore(course_key):
    """
    Get a learning_sequence.data.CourseOutlineData for a param:course_key
    """
    store = modulestore()

    with store.branch_setting(ModuleStoreEnum.Branch.published_only,
                              course_key):
        course = store.get_course(course_key, depth=2)
        sections_data = []
        for section in course.get_children():
            section_data = _make_section_data(section)
            sections_data.append(section_data)

        course_outline_data = CourseOutlineData(
            course_key=course_key,
            title=course.display_name_with_default,

            # subtree_edited_on has a tzinfo of bson.tz_util.FixedOffset (which
            # maps to UTC), but for consistency, we're going to use the standard
            # python timezone.utc (which is what the learning_sequence app will
            # return from MySQL). They will compare as equal.
            published_at=course.subtree_edited_on.replace(tzinfo=timezone.utc),

            # .course_version is a BSON obj, so we convert to str (MongoDB-
            # specific objects don't go into CourseOutlineData).
            published_version=str(course.course_version),
            entrance_exam_id=course.entrance_exam_id,
            days_early_for_beta=course.days_early_for_beta,
            sections=sections_data,
            self_paced=course.self_paced,
            course_visibility=CourseVisibility(course.course_visibility),
        )
    return course_outline_data
Exemple #2
0
def get_outline_from_modulestore(
        course_key) -> Tuple[CourseOutlineData, List[ContentErrorData]]:
    """
    Return a CourseOutlineData and list of ContentErrorData for param:course_key

    This function does not write any data as a side-effect. It generates a
    CourseOutlineData by inspecting the contents in the modulestore, but does
    not push that data anywhere. This function only operates on the published
    branch, and will not work on Old Mongo courses.
    """
    store = modulestore()
    content_errors = []

    with store.branch_setting(ModuleStoreEnum.Branch.published_only,
                              course_key):
        # Pull course with depth=3 so we prefetch Section -> Sequence -> Unit
        course = store.get_course(course_key, depth=3)
        sections_data = []
        unique_sequences = {}
        for section in course.get_children():
            section_data, section_errors, unique_sequences = _make_section_data(
                section, unique_sequences)
            if section_data:
                sections_data.append(section_data)
            content_errors.extend(section_errors)

        course_outline_data = CourseOutlineData(
            course_key=course_key,
            title=course.display_name_with_default,

            # subtree_edited_on has a tzinfo of bson.tz_util.FixedOffset (which
            # maps to UTC), but for consistency, we're going to use the standard
            # python timezone.utc (which is what the learning_sequence app will
            # return from MySQL). They will compare as equal.
            published_at=course.subtree_edited_on.replace(tzinfo=timezone.utc),

            # .course_version is a BSON obj, so we convert to str (MongoDB-
            # specific objects don't go into CourseOutlineData).
            published_version=str(course.course_version),
            entrance_exam_id=course.entrance_exam_id,
            days_early_for_beta=course.days_early_for_beta,
            sections=sections_data,
            self_paced=course.self_paced,
            course_visibility=CourseVisibility(course.course_visibility),
        )

    return (course_outline_data, content_errors)