Exemple #1
0
def _get_highlights_for_next_section(course, start_date, target_date):
    """ Using the target date, retrieves highlights for the next section. """
    use_next_sections_highlights = False
    for index, section, weeks_to_complete in spaced_out_sections(course):
        # We calculate section due date ourselves (rather than grabbing the due attribute),
        # since not every section has a real due date (i.e. not all are graded), but we still
        # want to know when this section should have been completed by the learner.
        section_due_date = start_date + weeks_to_complete

        if section_due_date.date() == target_date:
            use_next_sections_highlights = True
        elif use_next_sections_highlights and not _section_has_highlights(
                section):
            raise CourseUpdateDoesNotExist(
                'Next section [{}] has no highlights for {}'.format(
                    section.display_name, course.id))
        elif use_next_sections_highlights:
            return section.highlights, index + 1

    if use_next_sections_highlights:
        raise CourseUpdateDoesNotExist(
            'Last section was reached. There are no more highlights for {}'.
            format(course.id))

    return None, None
Exemple #2
0
def _get_course_with_highlights(course_key):
    """ Gets Course descriptor iff highlights are enabled for the course """
    if not COURSE_UPDATE_WAFFLE_FLAG.is_enabled(course_key):
        raise CourseUpdateDoesNotExist(
            '{} Course Update Messages waffle flag is disabled.'.format(
                course_key))

    course_descriptor = _get_course_descriptor(course_key)
    if not course_descriptor.highlights_enabled_for_messaging:
        raise CourseUpdateDoesNotExist(
            '{} Course Update Messages are disabled.'.format(course_key))

    return course_descriptor
Exemple #3
0
def _get_course_module(course_descriptor, user):
    """ Gets course module that takes into account user state and permissions """
    # Adding courseware imports here to insulate other apps (e.g. schedules) to
    # avoid import errors.
    from lms.djangoapps.courseware.model_data import FieldDataCache
    from lms.djangoapps.courseware.module_render import get_module_for_descriptor

    # Fake a request to fool parts of the courseware that want to inspect it.
    request = get_request_or_stub()
    request.user = user

    # Now evil modulestore magic to inflate our descriptor with user state and
    # permissions checks.
    field_data_cache = FieldDataCache.cache_for_descriptor_descendents(
        course_descriptor.id,
        user,
        course_descriptor,
        depth=1,
        read_only=True,
    )
    course_module = get_module_for_descriptor(
        user,
        request,
        course_descriptor,
        field_data_cache,
        course_descriptor.id,
        course=course_descriptor,
    )
    if not course_module:
        raise CourseUpdateDoesNotExist('Course module {} not found'.format(
            course_descriptor.id))
    return course_module
Exemple #4
0
def _get_course_descriptor(course_key):
    """ Gets course descriptor from modulestore """
    course_descriptor = modulestore().get_course(course_key, depth=1)
    if course_descriptor is None:
        raise CourseUpdateDoesNotExist(
            'Course {} not found.'.format(course_key))
    return course_descriptor
Exemple #5
0
def _get_course_descriptor(course_key):
    course_descriptor = modulestore().get_course(course_key, depth=1)
    if course_descriptor is None:
        raise CourseUpdateDoesNotExist(
            u"Course {} not found.".format(course_key)
        )
    return course_descriptor
Exemple #6
0
def _get_course_with_highlights(course_key):
    # pylint: disable=missing-docstring
    if not COURSE_UPDATE_WAFFLE_FLAG.is_enabled(course_key):
        raise CourseUpdateDoesNotExist(
            u"%s Course Update Messages waffle flag is disabled.",
            course_key,
        )

    course_descriptor = _get_course_descriptor(course_key)
    if not course_descriptor.highlights_enabled_for_messaging:
        raise CourseUpdateDoesNotExist(
            u"%s Course Update Messages are disabled.",
            course_key,
        )

    return course_descriptor
Exemple #7
0
def _get_course_with_highlights(course_key):
    """ Gets Course descriptor iff highlights are enabled for the course """
    course_descriptor = _get_course_descriptor(course_key)
    if not course_descriptor.highlights_enabled_for_messaging:
        raise CourseUpdateDoesNotExist(
            '{} Course Update Messages are disabled.'.format(course_key))

    return course_descriptor
Exemple #8
0
def _get_highlights_for_week(sections, week_num, course_key):
    # assume each provided section maps to a single week
    num_sections = len(sections)
    if not (1 <= week_num <= num_sections):
        raise CourseUpdateDoesNotExist(
            u"Requested week {} but {} has only {} sections.".format(
                week_num, course_key, num_sections))

    section = sections[week_num - 1]
    return section.highlights
Exemple #9
0
def _get_highlights_for_week(sections, week_num, course_key):
    """ Gets highlights from the section at week num """
    # assume each provided section maps to a single week
    num_sections = len(sections)
    if not 1 <= week_num <= num_sections:
        raise CourseUpdateDoesNotExist(
            'Requested week {} but {} has only {} sections.'.format(
                week_num, course_key, num_sections))

    section = sections[week_num - 1]
    return section.highlights
def _get_highlights_for_next_section(sections, course_key, target_date):
    sorted_sections = sorted(sections, key=lambda section: section.due)
    for index, sorted_section in enumerate(sorted_sections):
        if sorted_section.due.date(
        ) == target_date and index + 1 < len(sorted_sections):
            # Return index + 2 for "week_num", since weeks start at 1 as opposed to indexes,
            # and we want the next week, so +1 for index and +1 for next
            return sections[index + 1].highlights, index + 2
    raise CourseUpdateDoesNotExist(
        u"No section found ending on {} for {}".format(target_date,
                                                       course_key))
def get_week_highlights(user, course_key, week_num):
    """
    Get highlights (list of unicode strings) for a given week.
    week_num starts at 1.
    Raises CourseUpdateDoesNotExist if highlights do not exist for
    the requested week_num.
    """
    if not COURSE_UPDATE_WAFFLE_FLAG.is_enabled(course_key):
        raise CourseUpdateDoesNotExist(
            "%s does not have Course Updates enabled.",
            course_key
        )

    course_descriptor = _get_course_descriptor(course_key)
    course_module = _get_course_module(course_descriptor, user)
    sections_with_highlights = _get_sections_with_highlights(course_module)
    highlights = _get_highlights_for_week(sections_with_highlights, week_num, course_key)
    return highlights
def _get_highlights_for_next_section(course_module, sections, start_date, target_date):
    for index, section, weeks_to_complete in spaced_out_sections(course_module):
        if not _section_has_highlights(section):
            continue

        # We calculate section due date ourselves (rather than grabbing the due attribute),
        # since not every section has a real due date (i.e. not all are graded), but we still
        # want to know when this section should have been completed by the learner.
        section_due_date = start_date + weeks_to_complete

        if section_due_date.date() == target_date and index + 1 < len(sections):
            # Return index + 2 for "week_num", since weeks start at 1 as opposed to indexes,
            # and we want the next week, so +1 for index and +1 for next
            return sections[index + 1].highlights, index + 2

    raise CourseUpdateDoesNotExist(
        u"No section found ending on {} for {}".format(
            target_date, course_module.id
        )
    )
Exemple #13
0
def get_week_highlights(course_id, week_num):
    if COURSE_UPDATE_WAFFLE_FLAG.is_enabled(course_id):
        course = modulestore().get_course(course_id)
        return course.highlights_for_week(week_num)
    else:
        raise CourseUpdateDoesNotExist()
Exemple #14
0
def get_course_week_summary(course_id, week_num):
    if COURSE_UPDATE_WAFFLE_FLAG.is_enabled(course_id):
        course = modulestore().get_course(course_id)
        return course.week_summary(week_num)
    else:
        raise CourseUpdateDoesNotExist()