plugins.py 1.28 KB
Newer Older
1 2 3 4
"""
Registers the CCX feature for the edX platform.
"""

5
from django.conf import settings
6
from django.utils.translation import ugettext_noop
7

8
from xmodule.tabs import CourseTab
9
from student.roles import CourseCcxCoachRole
10
from courseware.access import has_access
11 12


13
class CcxCourseTab(CourseTab):
14
    """
15
    The representation of the CCX course tab
16 17
    """

18
    type = "ccx_coach"
19
    title = ugettext_noop("CCX Coach")
20
    view_name = "ccx_coach_dashboard"
21
    is_dynamic = True    # The CCX view is dynamically added to the set of tabs when it is enabled
22 23

    @classmethod
24
    def is_enabled(cls, course, user=None):
25 26 27 28
        """
        Returns true if CCX has been enabled and the specified user is a coach
        """
        if not settings.FEATURES.get('CUSTOM_COURSES_EDX', False) or not course.enable_ccx:
29
            # If ccx is not enable do not show ccx coach tab.
30
            return False
31 32 33

        is_staff_or_instructor = has_access(user, 'staff', course) or has_access(user, 'instructor', course)
        if hasattr(course.id, 'ccx') and is_staff_or_instructor:
34
            # if user is staff or instructor then he can always see ccx coach tab.
35
            return True
36

37
        # check if user has coach access.
38 39
        role = CourseCcxCoachRole(course.id)
        return role.has_user(user)