1010from cmsplugin_cascade import app_settings
1111from cmsplugin_cascade .bootstrap4 .grid import Breakpoint
1212from cmsplugin_cascade .forms import ManageChildrenFormMixin
13+ from cmsplugin_cascade .utils_helpers import CMS_ , get_ancestor
1314from .plugin_base import BootstrapPluginBase
1415from . import grid
1516
16-
1717def get_widget_choices ():
1818 breakpoints = app_settings .CMSPLUGIN_CASCADE ['bootstrap4' ]['fluid_bounds' ]
1919 widget_choices = []
@@ -104,6 +104,8 @@ def get_css_classes(cls, obj):
104104 def save_model (self , request , obj , form , change ):
105105 super ().save_model (request , obj , form , change )
106106 obj .sanitize_children ()
107+ obj .sanitize_related_siblings ()
108+
107109
108110plugin_pool .register_plugin (BootstrapContainerPlugin )
109111
@@ -127,9 +129,8 @@ class Meta:
127129class RowGridMixin (object ):
128130 def get_grid_instance (self ):
129131 row = grid .Bootstrap4Row ()
130- query = Q (plugin_type = 'BootstrapContainerPlugin' ) | Q (plugin_type = 'BootstrapColumnPlugin' ) \
131- | Q (plugin_type = 'BootstrapJumbotronPlugin' )
132- container = self .get_ancestors ().order_by ('depth' ).filter (query ).last ().get_bound_plugin ().get_grid_instance ()
132+ class_ancestor_name = ['BootstrapContainerPlugin' , 'BootstrapColumnPlugin' , 'BootstrapJumbotronPlugin' ]
133+ container = get_ancestor ( class_ancestor_name , plugin = self ).get_bound_plugin ().get_grid_instance ()
133134 container .add_row (row )
134135 return row
135136
@@ -161,11 +162,11 @@ class ColumnGridMixin(object):
161162 'xs-column-offset' , 'sm-column-offset' , 'md-column-offset' , 'lg-column-offset' , 'xs-column-offset' ]
162163 def get_grid_instance (self ):
163164 column = None
164- query = Q (plugin_type = 'BootstrapRowPlugin' )
165- row_obj = self .get_ancestors ().order_by ('depth' ).filter (query ).last ().get_bound_plugin ()
165+ row_obj = get_ancestor (['BootstrapRowPlugin' ], plugin = self ).get_bound_plugin ()
166166 # column_siblings = row_obj.get_descendants().order_by('depth').filter(plugin_type='BootstrapColumnPlugin')
167167 row = row_obj .get_grid_instance ()
168- for column_sibling in self .get_siblings ():
168+ siblings = self .parent .get_children ()
169+ for column_sibling in siblings :
169170 classes = [val for key , val in column_sibling .get_bound_plugin ().glossary .items ()
170171 if key in self .valid_keys and val ]
171172 if column_sibling .pk == self .pk :
@@ -195,17 +196,17 @@ def choose_help_text(*phrases):
195196 return phrases [1 ].format (bs4_breakpoints [first ].min )
196197 else :
197198 return phrases [2 ]
198-
199- if 'parent' in self . _cms_initial_attributes :
200- container = self ._cms_initial_attributes [ 'parent' ]. get_ancestors (). order_by ( 'depth' ). last (). get_bound_plugin ()
201- else :
202- containers = obj . get_ancestors (). filter ( plugin_type = 'BootstrapContainerPlugin' )
203- if containers :
204- container = containers . order_by ( 'depth' ). last (). get_bound_plugin ()
205- else :
206- jumbotrons = obj . get_ancestors (). filter ( plugin_type = 'BootstrapJumbotronPlugin' )
207- container = jumbotrons . order_by ( 'depth' ). last (). get_bound_plugin ()
208- breakpoints = container .glossary ['breakpoints' ]
199+
200+ container = get_ancestor ([ 'BootstrapContainerPlugin' , 'BootstrapJumbotronPlugin' ],
201+ _cms_initial_attributes = self ._cms_initial_attributes ,
202+ plugin = obj
203+ ). get_bound_plugin ( )
204+
205+ if 'breakpoints' in container . glossary :
206+ breakpoints = container . glossary [ 'breakpoints' ]
207+ elif 'media_queries' in container . glossary :
208+ #Case Jumbotron is first, its not has ancestor container
209+ breakpoints = list ( container .glossary ['media_queries' ]. keys ())
209210
210211 width_fields , offset_fields , reorder_fields , responsive_fields = {}, {}, {}, {}
211212 units = [ngettext_lazy ("{} unit" , "{} units" , i ).format (i ) for i in range (0 , 13 )]
@@ -334,9 +335,14 @@ class Meta:
334335 def save_model (self , request , obj , form , change ):
335336 super ().save_model (request , obj , form , change )
336337 obj .sanitize_children ()
338+ if not CMS_ :
339+ obj .sanitize_related_siblings ()
340+
341+ def sanitize_related_siblings_model (self ):
342+ self .sanitize_related_siblings ()
337343
338344 @classmethod
339- def sanitize_model (cls , obj ):
345+ def sanitize_model (cls ,obj ):
340346 sanitized = super ().sanitize_model (obj )
341347 return sanitized
342348
0 commit comments