1+ import importlib
12from collections import namedtuple
3+ from typing import Callable
24
35from cms .api import add_plugin
46from cms .models import CMSPlugin
@@ -66,6 +68,7 @@ def restore(self, placeholder, language, parent=None):
6668 target = parent ,
6769 ** data ,
6870 )
71+ self ._call_user_site_import_processor_if_necessary (plugin , self .data )
6972
7073 field = ("target" ,) if plugin_target else ()
7174 # An empty *update_fields* iterable will skip the save
@@ -91,3 +94,23 @@ def restore(self, placeholder, language, parent=None):
9194
9295 plugin .save ()
9396 return plugin
97+
98+ def _call_user_site_import_processor_if_necessary (
99+ self , plugin : CMSPlugin , plugin_data : dict
100+ ):
101+ # customize plugin-data on import with configured function
102+ if processor_symbol := getattr (
103+ settings , "DJANGOCMS_TRANSFER_PROCESS_IMPORT_PLUGIN_DATA" , None
104+ ):
105+ function = self ._resolve_function_from_full_path (processor_symbol )
106+ function (plugin , plugin_data )
107+
108+ def _resolve_function_from_full_path (
109+ self , fully_qualified_path : str
110+ ) -> Callable :
111+ try :
112+ module_name , function_name = fully_qualified_path .rsplit ("." , 1 )
113+ module = importlib .import_module (module_name )
114+ return getattr (module , function_name )
115+ except (AttributeError , ImportError ):
116+ raise ImportError (f"could not resolve { fully_qualified_path } " )
0 commit comments