29
29
from openedx .core .djangoapps .site_configuration import helpers as configuration_helpers
30
30
import openedx .core .djangoapps .content_staging .api as content_staging_api
31
31
import openedx .core .djangoapps .content_tagging .api as content_tagging_api
32
+ from openedx .core .lib .xblock_serializer .api import XBlockSerializer
33
+ from openedx .core .djangoapps .content_staging .data import LIBRARY_SYNC_PURPOSE
32
34
33
35
from .utils import reverse_course_url , reverse_library_url , reverse_usage_url
34
36
@@ -335,7 +337,7 @@ def import_staged_content_from_user_clipboard(parent_key: UsageKey, request) ->
335
337
return new_xblock , notices
336
338
337
339
338
- def import_staged_content_for_library_sync (downstream_xblock : XBlock , lib_block : XBlock , request ) -> StaticFileNotices :
340
+ def import_static_assets_for_library_sync (downstream_xblock : XBlock , lib_block : XBlock , request ) -> StaticFileNotices :
339
341
"""
340
342
Import the static assets from the library xblock to the downstream xblock
341
343
through staged content. Also updates the OLX references to point to the new
@@ -346,21 +348,26 @@ def import_staged_content_for_library_sync(downstream_xblock: XBlock, lib_block:
346
348
Returns a summary of changes made to static files in the destination
347
349
course.
348
350
"""
351
+ if not XBlockSerializer (
352
+ lib_block ,
353
+ fetch_asset_data = True ,
354
+ ).static_files :
355
+ return StaticFileNotices ()
349
356
if not content_staging_api :
350
357
raise RuntimeError ("The required content_staging app is not installed" )
351
- staged_content = content_staging_api .stage_xblock_temporarily (lib_block , request .user .id )
358
+ staged_content = content_staging_api .stage_xblock_temporarily (lib_block , request .user .id , LIBRARY_SYNC_PURPOSE )
352
359
if not staged_content :
353
360
# expired/error/loading
354
361
return StaticFileNotices ()
355
362
356
363
store = modulestore ()
357
- with store . bulk_operations ( downstream_xblock . context_key ) :
358
- # Now handle static files that need to go into Files & Uploads.
359
- # If the required files already exist, nothing will happen besides updating the olx .
360
- try :
364
+ try :
365
+ with store . bulk_operations ( downstream_xblock . context_key ):
366
+ # Now handle static files that need to go into Files & Uploads .
367
+ # If the required files already exist, nothing will happen besides updating the olx.
361
368
notices = _insert_static_files_into_downstream_xblock (downstream_xblock , staged_content .id , request )
362
- finally :
363
- staged_content .delete ()
369
+ finally :
370
+ staged_content .delete ()
364
371
365
372
return notices
366
373
0 commit comments