File tree Expand file tree Collapse file tree 4 files changed +52
-1
lines changed
project_styleguide/templates/patterns/molecules/streamfield/blocks Expand file tree Collapse file tree 4 files changed +52
-1
lines changed Original file line number Diff line number Diff line change 4
4
< div class ="promo-block__content ">
5
5
{% include "patterns/atoms/section-title/section-title.html" with title=value.title classes="promo-block__title" %}
6
6
< p class ="promo-block__description "> {{ value.description }}</ p >
7
- < a href ="{{ value.get_button_link }} " class ="button promo-block__button "> {{ value.button_text }}</ a >
7
+ {% if value.button_text %}
8
+ < a href ="{{ value.get_button_link }} " class ="button promo-block__button "> {{ value.button_text }}</ a >
9
+ {% endif %}
8
10
{% if value.secondary_link %}
9
11
< hr class ="promo-block__divider " aria-hidden ="true " />
10
12
{% with secondary_link=value.secondary_link.0.value %}
Original file line number Diff line number Diff line change @@ -69,9 +69,23 @@ class ServiceStoryBlock(StoryBlock):
69
69
)
70
70
71
71
72
+ class OptionalLinkPromoBlock (PromoBlock ):
73
+ """
74
+ Identical to PromoBlock in all aspects, except that button_link is optional.
75
+ """
76
+
77
+ button_text = blocks .CharBlock (max_length = 55 , required = False )
78
+ button_link = blocks .StreamBlock (
79
+ PromoBlock .declared_blocks ["button_link" ].child_blocks .items (),
80
+ required = False ,
81
+ max_num = 1 ,
82
+ )
83
+
84
+
72
85
class ServiceAreaStoryBlock (StoryBlock ):
73
86
blog_chooser = BlogChooserBlock ()
74
87
four_photo_collage = FourPhotoCollageBlock ()
75
88
key_points = IconKeyPointsBlock (label = "Key points with icons" )
76
89
link_columns = LinkColumnsBlock ()
90
+ promo = OptionalLinkPromoBlock ()
77
91
work_chooser = WorkChooserBlock ()
Original file line number Diff line number Diff line change
1
+ from django .test import SimpleTestCase
2
+
3
+ from wagtail .blocks .struct_block import StructBlockValidationError
4
+
5
+ from tbx .services .blocks import OptionalLinkPromoBlock , PromoBlock
6
+
7
+
8
+ class OptionalLinkPromoBlockTestCase (SimpleTestCase ):
9
+ def test_basic_promo_block_button_link_required (self ):
10
+ try :
11
+ PromoBlock ().clean ({"button_link" : []})
12
+ except StructBlockValidationError :
13
+ pass
14
+ else :
15
+ self .fail ("PromoBlock.button_link should be required" )
16
+
17
+ def test_custom_promo_block_button_link_optional (self ):
18
+ try :
19
+ OptionalLinkPromoBlock ().clean ({"button_link" : []})
20
+ except StructBlockValidationError as e :
21
+ self .fail (e .as_json_data ())
22
+
23
+ def test_basic_promo_block_button_text_required (self ):
24
+ try :
25
+ PromoBlock ().clean ({"button_text" : "" })
26
+ except StructBlockValidationError :
27
+ pass
28
+ else :
29
+ self .fail ("PromoBlock.button_text should be required" )
30
+
31
+ def test_custom_promo_block_button_text_optional (self ):
32
+ try :
33
+ OptionalLinkPromoBlock ().clean ({"button_text" : "" })
34
+ except StructBlockValidationError as e :
35
+ self .fail (e .as_json_data ())
You can’t perform that action at this time.
0 commit comments