@@ -137,6 +137,16 @@ def copy(self):
137137 def to_json (self ):
138138 return json .dumps (self .value )
139139
140+ def add (self , block ):
141+ model_class = block .__class__
142+ options = _get_default_options (model_class )
143+ self .value .append ({
144+ "id" : block .id ,
145+ "options" : options ,
146+ "unique_id" : uuid4 ().hex [:6 ],
147+ "model_name" : model_class .__name__
148+ })
149+
140150 @cached_property
141151 def help_text (self ):
142152 return ADMIN_HELP_TEXT
@@ -197,6 +207,14 @@ def _check_subblocks(obj):
197207 if changed :
198208 obj .save ()
199209
210+ def _get_default_options (model_class ):
211+ options = model_class .options if hasattr (model_class , "options" ) else BLOCK_OPTIONS
212+ if hasattr (model_class , "extra_options" ):
213+ options = deepcopy (options )
214+ options .update (model_class .extra_options )
215+ options = { k : v ['default' ] for k , v in options .items () if bool (v .get ('default' )) }
216+ return options
217+
200218def _copy (model_class , model_str , content , ctx ):
201219 as_list = ctx ['as_list' ]
202220 resp = dict (
@@ -249,11 +267,7 @@ def migrate_stream_options(stream_obj):
249267 stream_dict = stream_obj .from_json ()
250268 for b in stream_dict :
251269 model_class = get_model_by_string (b ['model_name' ])
252- options = model_class .options if hasattr (model_class , "options" ) else BLOCK_OPTIONS
253- if hasattr (model_class , "extra_options" ):
254- options = deepcopy (options )
255- options .update (model_class .extra_options )
256- options = { k : v ['default' ] for k , v in options .items () if bool (v .get ('default' )) }
270+ options = _get_default_options (model_class )
257271 options .update (b ['options' ])
258272 b ['options' ] = options
259273 return StreamObject (
0 commit comments