@@ -607,7 +607,14 @@ def test_get_placeholder_conf(self):
607
607
'main' : {
608
608
'name' : 'main content' ,
609
609
'plugins' : ['TextPlugin' , 'LinkPlugin' ],
610
- 'require_parent' : False ,
610
+ 'default_plugins' : [
611
+ {
612
+ 'plugin_type' : 'TextPlugin' ,
613
+ 'values' : {
614
+ 'body' : '<p>Some default text</p>'
615
+ },
616
+ },
617
+ ],
611
618
},
612
619
'layout/home.html main' : {
613
620
'name' : 'main content with FilerImagePlugin and limit' ,
@@ -642,8 +649,8 @@ def test_get_placeholder_conf(self):
642
649
returned = get_placeholder_conf ('excluded_plugins' , 'main' , 'layout/other.html' )
643
650
self .assertEqual (returned , TEST_CONF ['layout/other.html main' ]['excluded_plugins' ])
644
651
# test grandparent inherited value
645
- returned = get_placeholder_conf ('require_parent ' , 'main' , 'layout/other.html' )
646
- self .assertEqual (returned , TEST_CONF ['main' ]['require_parent ' ])
652
+ returned = get_placeholder_conf ('default_plugins ' , 'main' , 'layout/other.html' )
653
+ self .assertEqual (returned , TEST_CONF ['main' ]['default_plugins ' ])
647
654
# test generic configuration
648
655
returned = get_placeholder_conf ('plugins' , 'something' )
649
656
self .assertEqual (returned , TEST_CONF [None ]['plugins' ])
@@ -738,6 +745,79 @@ def test_placeholder_field_dynamic_slot_update(self):
738
745
self .assertEqual (old_placeholder_1_plugin_count , current_placeholder_1_plugin_count )
739
746
self .assertEqual (old_placeholder_2_plugin_count , current_placeholder_2_plugin_count )
740
747
748
+ def test_plugins_prepopulate (self ):
749
+ """ Tests prepopulate placeholder configuration """
750
+
751
+ conf = {
752
+ 'col_left' : {
753
+ 'default_plugins' : [
754
+ {
755
+ 'plugin_type' :'TextPlugin' ,
756
+ 'values' :{'body' :'<p>en default body 1</p>' },
757
+ },
758
+ {
759
+ 'plugin_type' :'TextPlugin' ,
760
+ 'values' :{'body' :'<p>en default body 2</p>' },
761
+ },
762
+ ]
763
+ },
764
+ }
765
+ with self .settings (CMS_PLACEHOLDER_CONF = conf ):
766
+ page = create_page ('page_en' , 'col_two.html' , 'en' )
767
+ placeholder = page .get_placeholders ("en" ).get (slot = 'col_left' )
768
+ context = SekizaiContext ()
769
+ context ['request' ] = self .get_request (language = "en" , page = page )
770
+ # Our page should have "en default body 1" AND "en default body 2"
771
+ content = _render_placeholder (placeholder , context )
772
+ self .assertRegexpMatches (content , "^<p>en default body 1</p>\s*<p>en default body 2</p>$" )
773
+
774
+ def test_plugins_children_prepopulate (self ):
775
+ """
776
+ Validate a default textplugin with a nested default link plugin
777
+ """
778
+
779
+ conf = {
780
+ 'col_left' : {
781
+ 'default_plugins' : [
782
+ {
783
+ 'plugin_type' : 'TextPlugin' ,
784
+ 'values' : {
785
+ 'body' : '<p>body %(_tag_child_1)s and %(_tag_child_2)s</p>'
786
+ },
787
+ 'children' : [
788
+ {
789
+ 'plugin_type' : 'LinkPlugin' ,
790
+ 'values' : {
791
+ 'name' : 'django' ,
792
+ 'external_link' : 'https://www.djangoproject.com/'
793
+ },
794
+ },
795
+ {
796
+ 'plugin_type' : 'LinkPlugin' ,
797
+ 'values' : {
798
+ 'name' : 'django-cms' ,
799
+ 'external_link' : 'https://www.django-cms.org'
800
+ },
801
+ },
802
+ ]
803
+ },
804
+ ]
805
+ },
806
+ }
807
+
808
+ with self .settings (CMS_PLACEHOLDER_CONF = conf ):
809
+ page = create_page ('page_en' , 'col_two.html' , 'en' )
810
+ placeholder = page .get_placeholders ("en" ).get (slot = 'col_left' )
811
+ context = SekizaiContext ()
812
+ context ['request' ] = self .get_request (language = "en" , page = page )
813
+ _render_placeholder (placeholder , context )
814
+ plugins = placeholder .get_plugins_list ()
815
+ self .assertEqual (len (plugins ), 3 )
816
+ self .assertEqual (plugins [0 ].plugin_type , 'TextPlugin' )
817
+ self .assertEqual (plugins [1 ].plugin_type , 'LinkPlugin' )
818
+ self .assertEqual (plugins [2 ].plugin_type , 'LinkPlugin' )
819
+ self .assertTrue (plugins [1 ].parent == plugins [2 ].parent and plugins [1 ].parent == plugins [0 ])
820
+
741
821
def test_placeholder_pk_thousands_format (self ):
742
822
page = create_page ("page" , "nav_playground.html" , "en" )
743
823
title = page .get_content_obj ("en" )
0 commit comments