def test_can_skip_entrance_exam_with_anonymous_user(self): """ Test can_skip_entrance_exam method with anonymous user """ self.assertFalse( user_can_skip_entrance_exam(self.request, self.anonymous_user, self.course))
def get_course_tab_list(request, course): """ Retrieves the course tab list from xmodule.tabs and manipulates the set as necessary """ user = request.user xmodule_tab_list = CourseTabList.iterate_displayable(course, user=user) # Now that we've loaded the tabs for this course, perform the Entrance Exam work. # If the user has to take an entrance exam, we'll need to hide away all but the # "Courseware" tab. The tab is then renamed as "Entrance Exam". course_tab_list = [] must_complete_ee = not user_can_skip_entrance_exam(user, course) for tab in xmodule_tab_list: if must_complete_ee: # Hide all of the tabs except for 'Courseware' # Rename 'Courseware' tab to 'Entrance Exam' if tab.type != 'courseware': continue tab.name = _("Entrance Exam") if tab.type == 'static_tab' and tab.course_staff_only and \ not bool(user and has_access(user, 'staff', course, course.id)): continue course_tab_list.append(tab) # Add in any dynamic tabs, i.e. those that are not persisted course_tab_list += _get_dynamic_tabs(course, user) return course_tab_list
def get_course_tab_list(request, course): """ Retrieves the course tab list from xmodule.tabs and manipulates the set as necessary """ user = request.user xmodule_tab_list = CourseTabList.iterate_displayable(course, user=user) # Now that we've loaded the tabs for this course, perform the Entrance Exam work. # If the user has to take an entrance exam, we'll need to hide away all but the # "Courseware" tab. The tab is then renamed as "Entrance Exam". course_tab_list = [] must_complete_ee = not user_can_skip_entrance_exam(user, course) for tab in xmodule_tab_list: if must_complete_ee: # Hide all of the tabs except for 'Courseware' # Rename 'Courseware' tab to 'Entrance Exam' if tab.type != 'courseware': continue tab.name = _("Entrance Exam") if tab.type == 'static_tab' and tab.course_staff_only and \ not bool(user and has_access(user, 'staff', course, course.id)): continue course_tab_list.append(tab) # Add in any dynamic tabs, i.e. those that are not persisted course_tab_list += _get_dynamic_tabs(course, user) return course_tab_list
def _reset_section_to_exam_if_required(self): """ Check to see if an Entrance Exam is required for the user. """ if not user_can_skip_entrance_exam(self.effective_user, self.course): exam_chapter = get_entrance_exam_content(self.effective_user, self.course) if exam_chapter and exam_chapter.get_children(): exam_section = exam_chapter.get_children()[0] if exam_section: self.chapter_url_name = exam_chapter.url_name self.section_url_name = exam_section.url_name
def test_can_skip_entrance_exam_with_anonymous_user(self): """ Test can_skip_entrance_exam method with anonymous user """ self.assertFalse(user_can_skip_entrance_exam(self.anonymous_user, self.course))
def toc_for_course(user, request, course, active_chapter, active_section, field_data_cache): ''' Create a table of contents from the module store Return format: { 'chapters': [ {'display_name': name, 'url_name': url_name, 'sections': SECTIONS, 'active': bool}, ], 'previous_of_active_section': {..}, 'next_of_active_section': {..} } where SECTIONS is a list [ {'display_name': name, 'url_name': url_name, 'format': format, 'due': due, 'active' : bool, 'graded': bool}, ...] where previous_of_active_section and next_of_active_section have information on the next/previous sections of the active section. active is set for the section and chapter corresponding to the passed parameters, which are expected to be url_names of the chapter+section. Everything else comes from the xml, or defaults to "". chapters with name 'hidden' are skipped. NOTE: assumes that if we got this far, user has access to course. Returns None if this is not the case. field_data_cache must include data from the course module and 2 levels of its descendants ''' with modulestore().bulk_operations(course.id): course_module = get_module_for_descriptor( user, request, course, field_data_cache, course.id, course=course ) if course_module is None: return None, None, None toc_chapters = list() chapters = course_module.get_display_items() # Check for content which needs to be completed # before the rest of the content is made available required_content = milestones_helpers.get_required_content(course.id, user) # The user may not actually have to complete the entrance exam, if one is required if user_can_skip_entrance_exam(user, course): required_content = [content for content in required_content if not content == course.entrance_exam_id] previous_of_active_section, next_of_active_section = None, None last_processed_section, last_processed_chapter = None, None found_active_section = False for chapter in chapters: # Only show required content, if there is required content # chapter.hide_from_toc is read-only (bool) display_id = slugify(chapter.display_name_with_default_escaped) local_hide_from_toc = False if required_content: if unicode(chapter.location) not in required_content: local_hide_from_toc = True # Skip the current chapter if a hide flag is tripped if chapter.hide_from_toc or local_hide_from_toc: continue sections = list() for section in chapter.get_display_items(): # skip the section if it is hidden from the user if section.hide_from_toc: continue is_section_active = (chapter.url_name == active_chapter and section.url_name == active_section) if is_section_active: found_active_section = True section_context = { 'display_name': section.display_name_with_default_escaped, 'url_name': section.url_name, 'format': section.format if section.format is not None else '', 'due': section.due, 'active': is_section_active, 'graded': section.graded, } _add_timed_exam_info(user, course, section, section_context) # update next and previous of active section, if applicable if is_section_active: if last_processed_section: previous_of_active_section = last_processed_section.copy() previous_of_active_section['chapter_url_name'] = last_processed_chapter.url_name elif found_active_section and not next_of_active_section: next_of_active_section = section_context.copy() next_of_active_section['chapter_url_name'] = chapter.url_name sections.append(section_context) last_processed_section = section_context last_processed_chapter = chapter toc_chapters.append({ 'display_name': chapter.display_name_with_default_escaped, 'display_id': display_id, 'url_name': chapter.url_name, 'sections': sections, 'active': chapter.url_name == active_chapter }) return { 'chapters': toc_chapters, 'previous_of_active_section': previous_of_active_section, 'next_of_active_section': next_of_active_section, }
def toc_for_course(user, request, course, active_chapter, active_section, field_data_cache): ''' Create a table of contents from the module store Return format: { 'chapters': [ {'display_name': name, 'url_name': url_name, 'sections': SECTIONS, 'active': bool}, ], 'previous_of_active_section': {..}, 'next_of_active_section': {..} } where SECTIONS is a list [ {'display_name': name, 'url_name': url_name, 'format': format, 'due': due, 'active' : bool, 'graded': bool}, ...] where previous_of_active_section and next_of_active_section have information on the next/previous sections of the active section. active is set for the section and chapter corresponding to the passed parameters, which are expected to be url_names of the chapter+section. Everything else comes from the xml, or defaults to "". chapters with name 'hidden' are skipped. NOTE: assumes that if we got this far, user has access to course. Returns None if this is not the case. field_data_cache must include data from the course module and 2 levels of its descendants ''' with modulestore().bulk_operations(course.id): course_module = get_module_for_descriptor( user, request, course, field_data_cache, course.id, course=course ) if course_module is None: return None, None, None toc_chapters = list() chapters = course_module.get_display_items() # Check for content which needs to be completed # before the rest of the content is made available required_content = milestones_helpers.get_required_content(course.id, user) # The user may not actually have to complete the entrance exam, if one is required if user_can_skip_entrance_exam(user, course): required_content = [content for content in required_content if not content == course.entrance_exam_id] previous_of_active_section, next_of_active_section = None, None last_processed_section, last_processed_chapter = None, None found_active_section = False for chapter in chapters: # Only show required content, if there is required content # chapter.hide_from_toc is read-only (bool) display_id = slugify(chapter.display_name_with_default_escaped) local_hide_from_toc = False if required_content: if unicode(chapter.location) not in required_content: local_hide_from_toc = True # Skip the current chapter if a hide flag is tripped if chapter.hide_from_toc or local_hide_from_toc: continue sections = list() for section in chapter.get_display_items(): # skip the section if it is hidden from the user if section.hide_from_toc: continue is_section_active = (chapter.url_name == active_chapter and section.url_name == active_section) if is_section_active: found_active_section = True section_context = { 'display_name': section.display_name_with_default_escaped, 'url_name': section.url_name, 'format': section.format if section.format is not None else '', 'due': section.due, 'active': is_section_active, 'graded': section.graded, } _add_timed_exam_info(user, course, section, section_context) # update next and previous of active section, if applicable if is_section_active: if last_processed_section: previous_of_active_section = last_processed_section.copy() previous_of_active_section['chapter_url_name'] = last_processed_chapter.url_name elif found_active_section and not next_of_active_section: next_of_active_section = section_context.copy() next_of_active_section['chapter_url_name'] = chapter.url_name sections.append(section_context) last_processed_section = section_context last_processed_chapter = chapter toc_chapters.append({ 'display_name': chapter.display_name_with_default_escaped, 'display_id': display_id, 'url_name': chapter.url_name, 'sections': sections, 'active': chapter.url_name == active_chapter }) return { 'chapters': toc_chapters, 'previous_of_active_section': previous_of_active_section, 'next_of_active_section': next_of_active_section, }