def courses_custom(request): """ Render "find courses" page. The course selection work is done in courseware.courses. """ courses_list = [] programs_list = [] course_discovery_meanings = getattr(settings, 'COURSE_DISCOVERY_MEANINGS', {}) if not settings.FEATURES.get('ENABLE_COURSE_DISCOVERY'): current_date = datetime.now(utc) courses_list = get_courses( request.user, filter_={'end__gte': current_date.date() - timedelta(days=1)}) if configuration_helpers.get_value( "ENABLE_COURSE_SORTING_BY_START_DATE", settings.FEATURES["ENABLE_COURSE_SORTING_BY_START_DATE"]): courses_list = sort_by_start_date(courses_list) else: courses_list = sort_by_announcement(courses_list) # Getting all the programs from course-catalog service. The programs_list is being added to the context but it's # not being used currently in courseware/courses.html. To use this list, you need to create a custom theme that # overrides courses.html. The modifications to courses.html to display the programs will be done after the support # for edx-pattern-library is added. if configuration_helpers.get_value( "DISPLAY_PROGRAMS_ON_MARKETING_PAGES", settings.FEATURES.get("DISPLAY_PROGRAMS_ON_MARKETING_PAGES")): programs_list = get_programs_data(request.user) if request.user.is_authenticated(): add_tag_to_enrolled_courses(request.user, courses_list) for course in courses_list: course_key = SlashSeparatedCourseKey.from_deprecated_string( course.id.to_deprecated_string()) with modulestore().bulk_operations(course_key): if has_access(request.user, 'load', course): access_link = get_last_accessed_courseware( get_course_by_id(course_key, 0), request, request.user) first_chapter_url, first_section = get_course_related_keys( request, get_course_by_id(course_key, 0)) first_target = reverse('courseware_section', args=[ course.id.to_deprecated_string(), first_chapter_url, first_section ]) course.course_target = access_link if access_link != None else first_target else: course.course_target = '/courses/' + course.id.to_deprecated_string( ) return render_to_response( "courseware/courses.html", { 'courses': courses_list, 'course_discovery_meanings': course_discovery_meanings, 'programs_list': programs_list })
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) return render_to_response('index.html', context)
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)