Implement a stub unified course tab

This commit is contained in:
Andy Armstrong
2017-01-30 22:52:03 -05:00
committed by Diana Huang
parent 6a85cd1a7c
commit 7862e375f1
5 changed files with 165 additions and 1 deletions

View File

@@ -2,6 +2,8 @@
This module is essentially a broker to xmodule/tabs.py -- it was originally introduced to
perform some LMS-specific tab display gymnastics for the Entrance Exams feature
"""
import waffle
from django.conf import settings
from django.utils.translation import ugettext as _, ugettext_noop
@@ -9,7 +11,7 @@ from courseware.access import has_access
from courseware.entrance_exams import user_must_complete_entrance_exam
from openedx.core.lib.course_tabs import CourseTabPluginManager
from student.models import CourseEnrollment
from xmodule.tabs import CourseTab, CourseTabList, key_checker
from xmodule.tabs import CourseTab, CourseTabList, key_checker, link_reverse_func
class EnrolledTab(CourseTab):
@@ -34,6 +36,16 @@ class CoursewareTab(EnrolledTab):
is_movable = False
is_default = False
@property
def link_func(self):
"""
Returns a function that computes the URL for this tab.
"""
if waffle.switch_is_active('unified_course_view'):
return link_reverse_func('unified_course_view')
else:
return link_reverse_func('courseware')
class CourseInfoTab(CourseTab):
"""

View File

@@ -25,6 +25,7 @@ from django.http import (
QueryDict,
)
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.utils.decorators import method_decorator
from django.utils.timezone import UTC
from django.utils.translation import ugettext as _
@@ -1623,3 +1624,55 @@ def financial_assistance_form(request):
}
],
})
class UnifiedCourseView(View):
"""
Unified view for a course.
"""
@method_decorator(login_required)
@method_decorator(ensure_csrf_cookie)
@method_decorator(cache_control(no_cache=True, no_store=True, must_revalidate=True))
@method_decorator(ensure_valid_course_key)
def get(self, request, course_id):
"""
Displays the main view for the specified course.
Arguments:
request: HTTP request
course_id (unicode): course id
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
# Render the outline as a fragment
outline_fragment = CourseOutlineFragmentView().render_fragment(request, course_id=course_id)
# Render the entire unified course view
context = {
'csrf': csrf(request)['csrf_token'],
'course': course,
'outline_fragment': outline_fragment,
'disable_courseware_js': True,
'uses_pattern_library': True,
}
return render_to_response('courseware/unified-course-view.html', context)
class CourseOutlineFragmentView(FragmentView):
"""
Course outline fragment to be shown in the unified course view.
"""
def render_fragment(self, request, course_id=None):
"""
Renders the course outline as a fragment.
"""
course_key = CourseKey.from_string(course_id)
course = get_course_with_access(request.user, 'load', course_key, check_if_enrolled=True)
context = {
'csrf': csrf(request)['csrf_token'],
'course': course,
}
html = render_to_string('courseware/course-outline.html', context)
return Fragment(html)