@@ -119,3 +119,59 @@ def upload_students_csv(_xblock_instance_args, _entry_id, course_id, task_input,
119119 upload_csv_to_report_store (rows , upload_filename , course_id , start_date , parent_dir = upload_parent_dir )
120120
121121 return task_progress .update_task_state (extra_meta = current_step )
122+
123+
124+ def upload_xblock_list_csv (_xblock_instance_args , _entry_id , course_id , task_input , action_name ):
125+ """
126+ generate a csv containing all xblocks in all courses
127+ """
128+ from openedx .core .djangoapps .content .course_overviews .models import CourseOverview
129+ from xmodule .modulestore .django import modulestore
130+
131+ start_time = time ()
132+ start_date = datetime .now (UTC )
133+ overviews = CourseOverview .objects .all ().order_by ('id' )
134+ total_courses = overviews .count ()
135+ task_progress = TaskProgress (action_name , total_courses , start_time )
136+
137+ current_step = {'step' : 'Calculating XBlock Info' }
138+ task_progress .update_task_state (extra_meta = current_step )
139+
140+
141+ data = []
142+ succeeded_count = 0
143+ for overview in overviews :
144+ try :
145+ course = modulestore ().get_course (overview .id )
146+ data .extend (
147+ {
148+ "Course ID" : course .id ,
149+ "Course Name" : course .display_name ,
150+ "Section Name" : section .display_name ,
151+ "Subsection Name" : subsection .display_name ,
152+ "Unit Name" : unit .display_name ,
153+ "Component Name" : component .display_name ,
154+ "Xblock Type" : component .location .block_type ,
155+ } for section in course .get_children () for subsection in section .get_children () for unit in subsection .get_children () for component in unit .get_children ()
156+ )
157+ succeeded_count += 1
158+ except :
159+ print (f"FAILED GETTING COURSE { overview .id } FROM MODULESTORE" )
160+
161+ header , rows = format_dictlist (data , ["Course ID" , "Course Name" , "Section Name" , "Subsection Name" , "Unit Name" , "Component Name" , "Xblock Type" ])
162+
163+ task_progress .attempted = total_courses
164+ task_progress .succeeded = succeeded_count
165+ task_progress .skipped = task_progress .failed = total_courses - succeeded_count
166+
167+ rows .insert (0 , header )
168+
169+ current_step = {'step' : 'Uploading CSV' }
170+ task_progress .update_task_state (extra_meta = current_step )
171+
172+ # Perform the upload
173+ upload_parent_dir = task_input .get ('upload_parent_dir' , '' )
174+ upload_filename = task_input .get ('filename' , 'xblocks_list' )
175+ upload_csv_to_report_store (rows , upload_filename , course_id , start_date , parent_dir = upload_parent_dir )
176+
177+ return task_progress .update_task_state (extra_meta = current_step )
0 commit comments