Example #1
0
def index(request, extra_context=None, user=AnonymousUser()):
    """
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup,
    as used by external_auth.
    """
    if extra_context is None:
        extra_context = {}

    courses = get_courses(user)

    if configuration_helpers.get_value(
            "ENABLE_COURSE_SORTING_BY_START_DATE",
            settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"],
    ):
        courses = sort_by_start_date(courses)
    else:
        courses = sort_by_announcement(courses)

    context = {'courses': courses}

    context['homepage_overlay_html'] = configuration_helpers.get_value(
        'homepage_overlay_html')

    # This appears to be an unused context parameter, at least for the master templates...
    context['show_partners'] = configuration_helpers.get_value(
        'show_partners', True)

    # TO DISPLAY A YOUTUBE WELCOME VIDEO
    # 1) Change False to True
    context['show_homepage_promo_video'] = configuration_helpers.get_value(
        'show_homepage_promo_video', False)

    # Maximum number of courses to display on the homepage.
    context['homepage_course_max'] = configuration_helpers.get_value(
        'HOMEPAGE_COURSE_MAX', settings.HOMEPAGE_COURSE_MAX)

    # 2) Add your video's YouTube ID (11 chars, eg "123456789xX"), or specify via site configuration
    # Note: This value should be moved into a configuration setting and plumbed-through to the
    # context via the site configuration workflow, versus living here
    youtube_video_id = configuration_helpers.get_value(
        'homepage_promo_video_youtube_id', "your-youtube-id")
    context['homepage_promo_video_youtube_id'] = youtube_video_id

    # allow for theme override of the courses list
    context['courses_list'] = theming_helpers.get_template_path(
        'courses_list.html')

    # Insert additional context for use in the template
    context.update(extra_context)

    # Add marketable programs to the context.
    context['programs_list'] = get_programs_with_type(request.site,
                                                      include_hidden=False)

    # TODO: Course Listing Plugin required
    context['journal_info'] = get_journals_context(request)

    return render_to_response('index.html', context)
Example #2
0
    def test_get_programs_with_type_include_hidden(self, include_hidden,
                                                   mock_get_program_types,
                                                   mock_get_programs):
        """Verify get_programs_with_type returns the expected list of programs with include_hidden parameter."""
        programs_with_program_type = []
        programs = [ProgramFactory(hidden=False), ProgramFactory(hidden=True)]
        program_types = []

        for program in programs:
            if program['hidden'] and not include_hidden:
                continue

            program_type = ProgramTypeFactory(name=program['type'])
            program_types.append(program_type)

            program_with_type = copy.deepcopy(program)
            program_with_type['type'] = program_type
            programs_with_program_type.append(program_with_type)

        mock_get_programs.return_value = programs
        mock_get_program_types.return_value = program_types

        actual = get_programs_with_type(self.site,
                                        include_hidden=include_hidden)
        self.assertEqual(actual, programs_with_program_type)
Example #3
0
def index(request, extra_context=None, user=AnonymousUser()):
    """
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup,
    as used by external_auth.
    """
    if extra_context is None:
        extra_context = {}

    courses = get_courses(user)

    if configuration_helpers.get_value(
            "ENABLE_COURSE_SORTING_BY_START_DATE",
            settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"],
    ):
        courses = sort_by_start_date(courses)
    else:
        courses = sort_by_announcement(courses)

    context = {'courses': courses}

    context['homepage_overlay_html'] = configuration_helpers.get_value('homepage_overlay_html')

    # This appears to be an unused context parameter, at least for the master templates...
    context['show_partners'] = configuration_helpers.get_value('show_partners', True)

    # TO DISPLAY A YOUTUBE WELCOME VIDEO
    # 1) Change False to True
    context['show_homepage_promo_video'] = configuration_helpers.get_value('show_homepage_promo_video', False)

    # Maximum number of courses to display on the homepage.
    context['homepage_course_max'] = configuration_helpers.get_value(
        'HOMEPAGE_COURSE_MAX', settings.HOMEPAGE_COURSE_MAX
    )

    # 2) Add your video's YouTube ID (11 chars, eg "123456789xX"), or specify via site configuration
    # Note: This value should be moved into a configuration setting and plumbed-through to the
    # context via the site configuration workflow, versus living here
    youtube_video_id = configuration_helpers.get_value('homepage_promo_video_youtube_id', "your-youtube-id")
    context['homepage_promo_video_youtube_id'] = youtube_video_id

    # allow for theme override of the courses list
    context['courses_list'] = theming_helpers.get_template_path('courses_list.html')

    # Insert additional context for use in the template
    context.update(extra_context)

    # Add marketable programs to the context.
    context['programs_list'] = get_programs_with_type(request.site, include_hidden=False)

    # TODO: Course Listing Plugin required
    context['journal_info'] = get_journals_context(request)

    return render_to_response('index.html', context)
Example #4
0
    def test_get_programs_with_type(self, mock_get_program_types, mock_get_programs):
        """Verify get_programs_with_type returns the expected list of programs."""
        programs_with_program_type = []
        programs = ProgramFactory.create_batch(2)
        program_types = []

        for program in programs:
            program_type = ProgramTypeFactory(name=program['type'])
            program_types.append(program_type)

            program_with_type = copy.deepcopy(program)
            program_with_type['type'] = program_type
            programs_with_program_type.append(program_with_type)

        mock_get_programs.return_value = programs
        mock_get_program_types.return_value = program_types

        actual = get_programs_with_type(self.site)
        self.assertEqual(actual, programs_with_program_type)
Example #5
0
    def test_get_programs_with_type(self, mock_get_program_types, mock_get_programs):
        """Verify get_programs_with_type returns the expected list of programs."""
        programs_with_program_type = []
        programs = ProgramFactory.create_batch(2)
        program_types = []

        for program in programs:
            program_type = ProgramTypeFactory(name=program['type'])
            program_types.append(program_type)

            program_with_type = copy.deepcopy(program)
            program_with_type['type'] = program_type
            programs_with_program_type.append(program_with_type)

        mock_get_programs.return_value = programs
        mock_get_program_types.return_value = program_types

        actual = get_programs_with_type(self.site)
        self.assertEqual(actual, programs_with_program_type)
Example #6
0
    def test_get_programs_with_type_include_hidden(self, include_hidden, mock_get_program_types, mock_get_programs):
        """Verify get_programs_with_type returns the expected list of programs with include_hidden parameter."""
        programs_with_program_type = []
        programs = [ProgramFactory(hidden=False), ProgramFactory(hidden=True)]
        program_types = []

        for program in programs:
            if program['hidden'] and not include_hidden:
                continue

            program_type = ProgramTypeFactory(name=program['type'])
            program_types.append(program_type)

            program_with_type = copy.deepcopy(program)
            program_with_type['type'] = program_type
            programs_with_program_type.append(program_with_type)

        mock_get_programs.return_value = programs
        mock_get_program_types.return_value = program_types

        actual = get_programs_with_type(self.site, include_hidden=include_hidden)
        self.assertEqual(actual, programs_with_program_type)
Example #7
0
def index(request, extra_context=None, user=AnonymousUser()):
    """
    Render the edX main page.

    extra_context is used to allow immediate display of certain modal windows, eg signup.
    """
    if extra_context is None:
        extra_context = {}

    courses = get_courses(user)

    if configuration_helpers.get_value(
            "ENABLE_COURSE_SORTING_BY_START_DATE",
            settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"],
    ):
        courses = sort_by_start_date(courses)
    else:
        courses = sort_by_announcement(courses)

    context = {'courses': courses}

    context['homepage_overlay_html'] = configuration_helpers.get_value(
        'homepage_overlay_html')

    # This appears to be an unused context parameter, at least for the master templates...
    context['show_partners'] = configuration_helpers.get_value(
        'show_partners', True)

    # TO DISPLAY A YOUTUBE WELCOME VIDEO
    # 1) Change False to True
    context['show_homepage_promo_video'] = configuration_helpers.get_value(
        'show_homepage_promo_video', False)

    # Maximum number of courses to display on the homepage.
    context['homepage_course_max'] = configuration_helpers.get_value(
        'HOMEPAGE_COURSE_MAX', settings.HOMEPAGE_COURSE_MAX)

    # 2) Add your video's YouTube ID (11 chars, eg "123456789xX"), or specify via site configuration
    # Note: This value should be moved into a configuration setting and plumbed-through to the
    # context via the site configuration workflow, versus living here
    youtube_video_id = configuration_helpers.get_value(
        'homepage_promo_video_youtube_id', "your-youtube-id")
    context['homepage_promo_video_youtube_id'] = youtube_video_id

    # allow for theme override of the courses list
    context['courses_list'] = theming_helpers.get_template_path(
        'courses_list.html')

    # Insert additional context for use in the template
    context.update(extra_context)

    # Add marketable programs to the context.
    context['programs_list'] = get_programs_with_type(request.site,
                                                      include_hidden=False)

    # Added by Mahendra
    from lms.djangoapps.specialization.models import categories
    from lms.djangoapps.course_extrainfo.models import course_extrainfo
    today = datetime.datetime.now(UTC).date()
    today_date_time = datetime.datetime.now(UTC)
    context["category_course_count"] = (course_extrainfo.objects.exclude(
        category="").values("category").annotate(
            ccount=Count("category")).filter(
                ccount__gte=1).order_by("-ccount")[:8])
    cat_course_count = (course_extrainfo.objects.exclude(
        category="").values("category").annotate(
            ccount=Count("category")).filter(
                ccount__gte=1).order_by("-ccount")[:8])
    categoryid = []
    for catid in cat_course_count:
        categoryid.append(catid["category"])
    context["categories_list"] = categories.objects.filter(
        pk__in=categoryid).values()

    # for lectures list
    lectures = course_extrainfo.objects.filter(course_type=2).values()
    cid = []
    for courseid in lectures:
        course_id = CourseKey.from_string(courseid["course_id"])
        cid.append(course_id)

    context["clectures"] = (CourseOverview.objects.all().filter(
        pk__in=cid,
        start__gte=today).exclude(catalog_visibility="none").order_by("start"))

    # for courses list
    index_courses = course_extrainfo.objects.filter(course_type=1).values()
    index_cid = []
    for index_course in index_courses:
        index_course_id = CourseKey.from_string(index_course["course_id"])
        index_cid.append(index_course_id)
        # log.info(u'course-id %s',index_course_id)
    # below query commented for displaying upcoming courses
    context["index_upcoming_courses"] = (CourseOverview.objects.all().filter(
        pk__in=index_cid, start__gte=today).order_by("start")[::-1])
    # query to display all courses
    context["index_ongoing_courses"] = (CourseOverview.objects.all().filter(
        pk__in=index_cid, start__lte=today_date_time,
        end__gte=today_date_time).order_by("start")[::-1])
    context["index_all"] = (CourseOverview.objects.all().exclude(
        catalog_visibility="none").order_by("start")[::-1][:10])
    # for upcoming case studies
    index_case_studies = course_extrainfo.objects.filter(
        course_type=3).values()
    index_csid = []
    for index_casestudy in index_case_studies:
        index_casestudy_id = CourseKey.from_string(
            index_casestudy["course_id"])
        index_csid.append(index_casestudy_id)
    context["index_upcoming_case_studies"] = (
        CourseOverview.objects.all().filter(
            pk__in=index_csid).order_by("start")[::-1])

    return render_to_response('index.html', context)