Skip to content

Commit 73860c9

Browse files
committed
add link option to image
1 parent 5d9f671 commit 73860c9

File tree

3 files changed

+45
-28
lines changed

3 files changed

+45
-28
lines changed

bakeup/pages/blocks.py

+34-27
Original file line numberDiff line numberDiff line change
@@ -44,32 +44,6 @@ class ColourThemeChoiceBlock(ChoiceBlock):
4444
]
4545

4646

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-
7347
class SpacerBlock(StructBlock):
7448
space = ChoiceBlock(
7549
choices=[(0, "0"), (1, "16px"), (2, "32px"), (3, "48px"), (4, "64px")],
@@ -107,7 +81,6 @@ class LinkTargetBlock(StreamBlock):
10781

10882
page = PageChooserBlock(label=_("Page"), icon="doc-empty-inverse")
10983
document = DocumentChooserBlock(label=_("Document"), icon="doc-full")
110-
image = ImageChooserBlock(label=_("Image"))
11184
link = CharBlock(label=_("Internal link"))
11285
url = URLBlock(label=_("External link"))
11386
anchor = CharBlock(
@@ -170,6 +143,40 @@ def required(self):
170143
return self.meta.required
171144

172145

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+
173180
class ButtonBlock(StructBlock):
174181
"""
175182
A button which acts like a link.

0 commit comments

Comments
 (0)