Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AnnotatedImageBlock to use LinkBlock #12481

Merged
merged 15 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
danielfmiranda marked this conversation as resolved.
Show resolved Hide resolved

Large diffs are not rendered by default.

Large diffs are not rendered by default.

236 changes: 207 additions & 29 deletions network-api/networkapi/reports/tests/test_block_type_report.py

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions network-api/networkapi/utility/faker/streamfield_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,17 @@ def generate_image_field():
image_id = choice(Image.objects.all()).id
alt_text = " ".join(fake.words(nb=5))
caption = " ".join(fake.words(nb=5))
caption_url = fake.url(schemes=["https"])
caption_external_url = [
danielfmiranda marked this conversation as resolved.
Show resolved Hide resolved
{
"link_to": "external_url",
"external_url": fake.url(schemes=["https"]),
"new_window": True,
}
]

return generate_field(
"image",
{
"image": image_id,
"altText": alt_text,
"caption": caption,
"captionURL": caption_url,
},
{"image": image_id, "altText": alt_text, "caption": caption, "caption_url": caption_external_url},
)


Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from wagtail import blocks

from .image_block import ImageBlock
from .link_block import LinkWithoutLabelBlock


class RadioSelectBlock(blocks.ChoiceBlock):
Expand All @@ -12,7 +13,9 @@ def __init__(self, *args, **kwargs):

class AnnotatedImageBlock(ImageBlock):
caption = blocks.CharBlock(required=False)
captionURL = blocks.CharBlock(required=False, help_text="Optional URL that this caption should link out to.")
caption_url = blocks.ListBlock(
LinkWithoutLabelBlock(), min_num=0, max_num=1, help_text="Optional URL that this caption should link out to."
)
image_width = RadioSelectBlock(
choices=(
("normal", "Normal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ class Meta:


register(BaseLinkBlockAdapter(), LinkBlock)


class LinkWithoutLabelBlock(LinkBlock):
def __init__(self, local_blocks=None, **kwargs):
super().__init__(local_blocks, **kwargs)
self.child_blocks = self.base_blocks.copy()
self.child_blocks.pop("label")


register(BaseLinkBlockAdapter(), LinkWithoutLabelBlock)
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@
<img src="{{ img.url }}" alt="{{ value.altText }}" class="tw-w-full {% if value.image_width == "full_width" %} tw-object-cover tw-object-center tw-max-h-[400px] large:tw-max-h-[550px] xlarge:tw-max-h-[650px] {% endif %}">
{% if value.caption %}
<figcaption class="tw-body-small tw-mt-4 tw-block {% if value.image_width == "full_width" %} tw-pl-6 {% endif %}">
{% if value.captionURL %}<a href="{{ value.captionURL }}">{% endif %}
{{ value.caption }}
{% if value.captionURL %}</a>{% endif %}
{% if value.caption_url %}
{% with link=value.caption_url.0 %}
<a href="{{ link.url }}" {% if link.new_window %}target="_blank"{% endif %}>{{ value.caption }}</a>
{% endwith %}
{% else %}
{{ value.caption }}
{% endif %}
</figcaption>
{% endif %}
</figure>
Expand Down
Loading