@@ -44,32 +44,6 @@ class ColourThemeChoiceBlock(ChoiceBlock):
44
44
]
45
45
46
46
47
- class ImageChooserBlock (StructBlock ):
48
- alignment = ImageAlignmentChoiceBlock (default = "start" )
49
- image = _ImageChooserBlock ()
50
-
51
- class Meta :
52
- template = "blocks/image_block.html"
53
- label = "Image"
54
- icon = "image"
55
-
56
- def get_context (self , value , parent_context = None ):
57
- context = super ().get_context (value , parent_context )
58
- if value .get ("alignment" ) == "center" :
59
- context .update (
60
- {
61
- "classes" : "img-fluid mx-auto d-block" ,
62
- }
63
- )
64
- else :
65
- context .update (
66
- {
67
- "classes" : "img-fluid float-{}" .format (value ),
68
- }
69
- )
70
- return context
71
-
72
-
73
47
class SpacerBlock (StructBlock ):
74
48
space = ChoiceBlock (
75
49
choices = [(0 , "0" ), (1 , "16px" ), (2 , "32px" ), (3 , "48px" ), (4 , "64px" )],
@@ -107,7 +81,6 @@ class LinkTargetBlock(StreamBlock):
107
81
108
82
page = PageChooserBlock (label = _ ("Page" ), icon = "doc-empty-inverse" )
109
83
document = DocumentChooserBlock (label = _ ("Document" ), icon = "doc-full" )
110
- image = ImageChooserBlock (label = _ ("Image" ))
111
84
link = CharBlock (label = _ ("Internal link" ))
112
85
url = URLBlock (label = _ ("External link" ))
113
86
anchor = CharBlock (
@@ -170,6 +143,40 @@ def required(self):
170
143
return self .meta .required
171
144
172
145
146
+ class ImageChooserBlock (StructBlock ):
147
+ image = _ImageChooserBlock ()
148
+ max_width = IntegerBlock (
149
+ required = False ,
150
+ help_text = _ ("Set a maximum width for the image in pixels." ),
151
+ min_value = 0 ,
152
+ )
153
+ alignment = ImageAlignmentChoiceBlock (default = "start" )
154
+ link = LinkBlock ()
155
+
156
+ class Meta :
157
+ template = "blocks/image_block.html"
158
+ label = "Image"
159
+ icon = "image"
160
+
161
+ def get_context (self , value , parent_context = None ):
162
+ context = super ().get_context (value , parent_context )
163
+ if value .get ("alignment" ) == "center" :
164
+ context .update (
165
+ {
166
+ "classes" : "img-fluid mx-auto d-block" ,
167
+ }
168
+ )
169
+ else :
170
+ context .update (
171
+ {
172
+ "classes" : "img-fluid float-{}" .format (value .get ("alignment" )),
173
+ }
174
+ )
175
+ if value .get ("max_width" ):
176
+ context ["max_width" ] = "max-width: {}px;" .format (value .get ("max_width" ))
177
+ return context
178
+
179
+
173
180
class ButtonBlock (StructBlock ):
174
181
"""
175
182
A button which acts like a link.
0 commit comments