def create_from_json(body: dict, download=False): module = Module(body['id'], body['name'], body['url'], download) for content in body['contents']: new_file = File.create_file_or_linkablecontent(content, download) if new_file is not None: module.add_content(new_file) return module
def populate_config(conn: Connection, config: Config): """ This function is responsible for adding the already present courses to the config. THIS FUNCTION MUTATES THE config PARAM :param conn: DB connection :param config: Moodle configuration """ rows = get_config_courses(conn, config.id) # Create the courses and populate each one # TODO test this code for row in rows: course = Course.create_from_db(row) # Create the sections and populate each one rows_sections = get_course_sections(conn, config.id, course.id) for r_section in rows_sections: section = Section.create_from_db(r_section) # Add the LinkableContents section.modules = __get_linkablecontents(conn, config.id, section.id, True) # Create the modules, populate each one and add them to the section rows_modules = get_section_modules(conn, config.id, section.id) for r_module in rows_modules: module = Module.create_from_db(r_module) # Add the LinkableContents module.contents = __get_linkablecontents( conn, config.id, module.id, False) # Add the Files rows_files = get_module_files(conn, config.id, module.id) for r_file in rows_files: module.add_content( File.create_file_or_linkablecontent(r_file)) # Add the module to the section section.add_module(module) # Add the section to the course course.add_section(section) # Add the course to the config config.add_course(course)