Example #1
0
 def is_enabled(cls, course, user=None):
     """
     The "Home" tab is not shown for the new unified course experience.
     """
     request = RequestCache.get_current_request()
     return not waffle.flag_is_active(request,
                                      UNIFIED_COURSE_EXPERIENCE_FLAG)
Example #2
0
 def link_func(self):
     """
     Returns a function that computes the URL for this tab.
     """
     request = RequestCache.get_current_request()
     url_name = self.main_course_url_name(request)
     return link_reverse_func(url_name)
Example #3
0
 def link_func(self):
     """
     Returns a function that computes the URL for this tab.
     """
     request = RequestCache.get_current_request()
     url_name = self.main_course_url_name(request)
     return link_reverse_func(url_name)
Example #4
0
def get_current_request():
    """
    Return current request instance.

    Returns:
         (HttpRequest): returns cirrent request
    """
    return RequestCache.get_current_request()
Example #5
0
def get_current_request():
    """
    Return current request instance.

    Returns:
         (HttpRequest): returns current request
    """
    return RequestCache.get_current_request()
Example #6
0
 def link_func(self):
     """
     Returns a function that computes the URL for this tab.
     """
     request = RequestCache.get_current_request()
     if waffle.flag_is_active(request, 'unified_course_view'):
         return link_reverse_func('edx.course_experience.course_home')
     else:
         return link_reverse_func('courseware')
Example #7
0
def default_course_url_name(request=None):
    """
    Returns the default course URL name for the current user.
    """
    if waffle.flag_is_active(request or RequestCache.get_current_request(),
                             UNIFIED_COURSE_VIEW_FLAG):
        return 'openedx.course_experience.course_home'
    else:
        return 'courseware'
Example #8
0
def course_home_url_name(request=None):
    """
    Returns the course home page's URL name for the current user.
    """
    if waffle.flag_is_active(request or RequestCache.get_current_request(),
                             UNIFIED_COURSE_EXPERIENCE_FLAG):
        return 'openedx.course_experience.course_home'
    else:
        return 'info'
Example #9
0
def get_request_user():
    """
    Helper to get the authenticated user from the current HTTP request (if
    applicable).

    If the requester of an unenrollment is not the same person as the student
    being unenrolled, we authenticate to the commerce service as the requester.
    """
    request = RequestCache.get_current_request()
    return getattr(request, 'user', None)
Example #10
0
def get_request_user():
    """
    Helper to get the authenticated user from the current HTTP request (if
    applicable).

    If the requester of an unenrollment is not the same person as the student
    being unenrolled, we authenticate to the commerce service as the requester.
    """
    request = RequestCache.get_current_request()
    return getattr(request, 'user', None)
Example #11
0
    def _create_courseware_context(self):
        """
        Returns and creates the rendering context for the courseware.
        Also returns the table of contents for the courseware.
        """
        request = RequestCache.get_current_request()
        courseware_context = {
            'csrf':
            csrf(self.request)['csrf_token'],
            'course':
            self.course,
            'init':
            '',
            'fragment':
            Fragment(),
            'staff_access':
            self.is_staff,
            'masquerade':
            self.masquerade,
            'supports_preview_menu':
            True,
            'studio_url':
            get_studio_url(self.course, 'course'),
            'xqa_server':
            settings.FEATURES.get('XQA_SERVER', "http://your_xqa_server.com"),
            'bookmarks_api_url':
            reverse('bookmarks'),
            'language_preference':
            self._get_language_preference(),
            'disable_optimizely':
            True,
            'section_title':
            None,
            'sequence_title':
            None,
            'disable_accordion':
            waffle.flag_is_active(request, UNIFIED_COURSE_VIEW_FLAG),
        }
        table_of_contents = toc_for_course(
            self.effective_user,
            self.request,
            self.course,
            self.chapter_url_name,
            self.section_url_name,
            self.field_data_cache,
        )
        courseware_context['accordion'] = render_accordion(
            self.request,
            self.course,
            table_of_contents['chapters'],
        )

        # entrance exam data
        self._add_entrance_exam_to_context(courseware_context)

        # staff masquerading data
        now = datetime.now(UTC())
        effective_start = _adjust_start_date_for_beta_testers(
            self.effective_user, self.course, self.course_key)
        if not in_preview_mode() and self.is_staff and now < effective_start:
            # Disable student view button if user is staff and
            # course is not yet visible to students.
            courseware_context['disable_student_access'] = True

        if self.section:
            # chromeless data
            if self.section.chrome:
                chrome = [
                    s.strip() for s in self.section.chrome.lower().split(",")
                ]
                if 'accordion' not in chrome:
                    courseware_context['disable_accordion'] = True
                if 'tabs' not in chrome:
                    courseware_context['disable_tabs'] = True

            # default tab
            if self.section.default_tab:
                courseware_context['default_tab'] = self.section.default_tab

            # section data
            courseware_context[
                'section_title'] = self.section.display_name_with_default
            section_context = self._create_section_context(
                table_of_contents['previous_of_active_section'],
                table_of_contents['next_of_active_section'],
            )
            courseware_context['fragment'] = self.section.render(
                STUDENT_VIEW, section_context)
            if self.section.position and self.section.has_children:
                display_items = self.section.get_display_items()
                if display_items:
                    try:
                        courseware_context['sequence_title'] = display_items[self.section.position - 1] \
                            .display_name_with_default
                    except IndexError:
                        log.info(
                            "Course section {} with position {} and total section display items: {}"
                            .format(
                                self.section.display_name_with_default,
                                self.section.position,
                                len(display_items),
                            ))
        return courseware_context