def _ungraded_structure(self, section_id=None, subsection_id=None): section_type_key = self.get_cache_key(u'sections_{}_{}'.format(section_id, subsection_id)) found_structure = cache.get(section_type_key) if not found_structure: all_sections_key = self.get_cache_key(u'sections') found_structure = cache.get(all_sections_key) if not found_structure: structure = self._structure() found_structure = CourseStructure.course_structure_to_sections(structure, graded=False) cache.set(all_sections_key, found_structure) for section in found_structure: self._add_submissions_and_part_ids(section['children'], self._build_ungraded_answer_distribution_url_func( section['id'])) self._build_submission_collections(section['children'], self._build_subsection_url_func(section['id'])) self._build_submission_collections(found_structure, self._build_section_url) if found_structure: if section_id: found_structure = [section for section in found_structure if section['id'] == section_id] if found_structure and subsection_id: found_structure = \ [section for section in found_structure[0]['children'] if section['id'] == subsection_id] cache.set(section_type_key, found_structure) return found_structure
def _get_sections(self): structure = self.course_api_client.course_structures(self.page.course_id).get() sections = CourseStructure.course_structure_to_sections(structure, graded=False) problems = self._get_problems_dict() for section in sections: self._build_submissions(section['children'], problems) return self._build_submissions(sections, problems)
def _get_sections(self): blocks = self.course_api_client.blocks().get() sections = CourseStructure.course_structure_to_sections(blocks, 'problem', graded=False) problems = self._get_problems_dict() for section in sections: self._build_submissions(section['children'], problems) return self._build_submissions(sections, problems)
def _get_sections(self): blocks = self.course_api_client.blocks().get() sections = CourseStructure.course_structure_to_sections(blocks, 'problem', graded=False) problems = self._get_problems_dict() for section in sections: self._build_submissions(section['children'], problems) return self._build_submissions(sections, problems)
def test_course_structure_to_sections(self): factory = CourseStructureFactory() structure = factory.structure actual = CourseStructure.course_structure_to_sections(structure, False) self.assertListEqual( actual, self._prepare_structure(structure, factory.sections, False))
def _get_sections(self): structure = self.course_api_client.course_structures( self.page.course_id).get() sections = CourseStructure.course_structure_to_sections(structure, graded=False) problems = self._get_problems_dict() for section in sections: self._build_submissions(section['children'], problems) return self._build_submissions(sections, problems)
def course_structure(self, section_id=None, subsection_id=None): """ Returns course structure from cache. If structure isn't found, it is fetched from the course structure API. If no arguments are provided, all sections and children are returned. If only section_id is provided, that section is returned. If both section_id and subsection_id is provided, the structure for the subsection is returned. """ if section_id is None and subsection_id is not None: raise ValueError( 'section_id must be specified if subsection_id is specified.') structure_type_key = self.get_cache_key( self.section_type_template.format(section_id, subsection_id)) found_structure = cache.get(structure_type_key) if not found_structure: all_sections_key = self.get_cache_key(self.all_sections_key) found_structure = cache.get(all_sections_key) if not found_structure: structure = self._get_structure() found_structure = CourseStructure.course_structure_to_sections( structure, self.module_type, graded=self.module_graded_type) cache.set(all_sections_key, found_structure) for section in found_structure: self.add_child_data_to_parent_blocks( section['children'], self.build_module_url_func(section['id'])) self.attach_data_to_parents( section['children'], self.build_subsection_url_func(section['id'])) section['num_modules'] = sum( child.get('num_modules', 0) for child in section['children']) self.attach_data_to_parents(found_structure, self.build_section_url) if found_structure: if section_id: found_structure = [ section for section in found_structure if section['id'] == section_id ] if found_structure and subsection_id: found_structure = \ [section for section in found_structure[0]['children'] if section['id'] == subsection_id] cache.set(structure_type_key, found_structure) return found_structure
def course_structure(self, section_id=None, subsection_id=None): """ Returns course structure from cache. If structure isn't found, it is fetched from the course structure API. If no arguments are provided, all sections and children are returned. If only section_id is provided, that section is returned. If both section_id and subsection_id is provided, the structure for the subsection is returned. """ if section_id is None and subsection_id is not None: raise ValueError('section_id must be specified if subsection_id is specified.') structure_type_key = self.get_cache_key(self.section_type_template.format(section_id, subsection_id)) found_structure = cache.get(structure_type_key) if not found_structure: all_sections_key = self.get_cache_key(self.all_sections_key) found_structure = cache.get(all_sections_key) if not found_structure: structure = self._get_structure() found_structure = CourseStructure.course_structure_to_sections(structure, self.module_type, graded=self.module_graded_type) cache.set(all_sections_key, found_structure) for section in found_structure: self.add_child_data_to_parent_blocks(section['children'], self.build_module_url_func(section['id'])) self.attach_data_to_parents(section['children'], self.build_subsection_url_func(section['id'])) section['num_modules'] = sum(child.get('num_modules', 0) for child in section['children']) self.attach_data_to_parents(found_structure, self.build_section_url) if found_structure: if section_id: found_structure = [section for section in found_structure if section['id'] == section_id] if found_structure and subsection_id: found_structure = \ [section for section in found_structure[0]['children'] if section['id'] == subsection_id] cache.set(structure_type_key, found_structure) return found_structure
def _ungraded_structure(self, section_id=None, subsection_id=None): section_type_key = self.get_cache_key(u'sections_{}_{}'.format( section_id, subsection_id)) found_structure = cache.get(section_type_key) if not found_structure: all_sections_key = self.get_cache_key(u'sections') found_structure = cache.get(all_sections_key) if not found_structure: structure = self._structure() found_structure = CourseStructure.course_structure_to_sections( structure, graded=False) cache.set(all_sections_key, found_structure) for section in found_structure: self._add_submissions_and_part_ids( section['children'], self._build_ungraded_answer_distribution_url_func( section['id'])) self._build_submission_collections( section['children'], self._build_subsection_url_func(section['id'])) self._build_submission_collections(found_structure, self._build_section_url) if found_structure: if section_id: found_structure = [ section for section in found_structure if section['id'] == section_id ] if found_structure and subsection_id: found_structure = \ [section for section in found_structure[0]['children'] if section['id'] == subsection_id] cache.set(section_type_key, found_structure) return found_structure
def test_course_structure_to_sections(self): factory = CourseStructureFactory() structure = factory.structure actual = CourseStructure.course_structure_to_sections(structure, False) self.assertListEqual(actual, self._prepare_structure(structure, factory.sections, False))