'Returns and creates the rendering context for the courseware.
Also returns the table of contents for the courseware.'

def _create_courseware_context(self, request):

    course_url_name = default_course_url_name(self.course.id)
    course_url = reverse(course_url_name, kwargs={'course_id': unicode(self.course.id)})
    courseware_context = {'csrf': csrf(self.request)['csrf_token'], 'course': self.course, 'course_url': course_url, 'chapter': self.chapter, 'section': self.section, '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': (not WaffleSwitchNamespace('RET').is_enabled('enable_optimizely_in_courseware')), 'section_title': None, 'sequence_title': None, 'disable_accordion': COURSE_OUTLINE_PAGE_FLAG.is_enabled(self.course.id)}
    courseware_context.update(get_experiment_user_metadata_context(request, self.course, self.effective_user))
    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'])
    courseware_context['course_sock_fragment'] = CourseSockFragmentView().render_to_fragment(request, course=self.course)
    self._add_entrance_exam_to_context(courseware_context)
    if (not check_course_open_for_learner(self.effective_user, self.course)):
        courseware_context['disable_student_access'] = True
        courseware_context['supports_preview_menu'] = False
    if self.section:
        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
        if self.section.default_tab:
            courseware_context['default_tab'] = self.section.default_tab
        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.exception('IndexError    loading    courseware    for    user    %s,    course    %s,    section    %s,    position    %d.    Total    items:    %d.    URL:    %s', self.real_user.username, self.course.id, self.section.display_name_with_default, self.section.position, len(display_items), self.url)
                    raise
    return courseware_context
