Updated ImageTeaserBlock to use LinkBlock (#12580)
* added new link_button field * added migration operation to transfer over old data to new field * removal of old field * squashed migrations * updated template * linting * updated migrations * migrations * migrations
This commit is contained in:
Родитель
91581e791c
Коммит
53801a3557
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -1,10 +1,12 @@
|
|||
from django.forms.utils import ErrorList
|
||||
from django.utils import functional as func_utils
|
||||
from django.utils import text as text_utils
|
||||
from wagtail import blocks
|
||||
from wagtail.blocks.struct_block import StructBlockValidationError
|
||||
from wagtail.images.blocks import ImageChooserBlock
|
||||
|
||||
from networkapi.wagtailpages.pagemodels.customblocks.link_button_block import (
|
||||
LinkButtonBlock,
|
||||
)
|
||||
|
||||
|
||||
class ImageTeaserValue(blocks.StructValue):
|
||||
@func_utils.cached_property
|
||||
|
@ -19,15 +21,7 @@ class ImageTeaserBlock(blocks.StructBlock):
|
|||
|
||||
altText = blocks.CharBlock(required=True, help_text="Image description (for screen readers).")
|
||||
|
||||
url_label = blocks.CharBlock(required=False)
|
||||
url = blocks.CharBlock(required=False)
|
||||
styling = blocks.ChoiceBlock(
|
||||
choices=[
|
||||
("btn-primary", "Primary button"),
|
||||
("btn-secondary", "Secondary button"),
|
||||
],
|
||||
default="btn-primary",
|
||||
)
|
||||
link_button = blocks.ListBlock(LinkButtonBlock(), min_num=0, max_num=1, help_text="Optional link button")
|
||||
top_divider = blocks.BooleanBlock(
|
||||
required=False,
|
||||
help_text="Optional divider above content block.",
|
||||
|
@ -51,19 +45,6 @@ class ImageTeaserBlock(blocks.StructBlock):
|
|||
context["divider_styles"] = " ".join(divider_styles)
|
||||
return context
|
||||
|
||||
def clean(self, value):
|
||||
result = super().clean(value)
|
||||
errors = {}
|
||||
|
||||
if value["url"] and not value["url_label"]:
|
||||
errors["url_label"] = ErrorList(["Please add a label value for the URL."])
|
||||
if value["url_label"] and not value["url"]:
|
||||
errors["url"] = ErrorList(["Please add a URL value for the link."])
|
||||
if errors:
|
||||
raise StructBlockValidationError(block_errors=errors)
|
||||
|
||||
return result
|
||||
|
||||
class Meta:
|
||||
label = "Image teaser"
|
||||
icon = "doc-full"
|
||||
|
|
|
@ -7,10 +7,12 @@
|
|||
<div class="tw-row-start-2 large:tw-row-start-1">
|
||||
<h2 class="tw-mb-8">{{ card.title }}<a href="#{{ card.slug }}"></a></h2>
|
||||
{{ card.text|richtext }}
|
||||
{% if card.url and card.url_label %}
|
||||
<a class="tw-{{ card.styling }} link-button tw-mt-8" href="{{ card.url }}">
|
||||
{{ card.url_label }}
|
||||
</a>
|
||||
{% if card.link_button %}
|
||||
{% with link_button=card.link_button.0 %}
|
||||
<a class="tw-{{ link_button.styling }} link-button tw-mt-8" href="{{ link_button.url }}" {% if link_button.new_window %}target="_blank"{% endif %}>
|
||||
{{ link_button.label }}
|
||||
</a>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
</div>
|
||||
<div class="tw-flex tw-items-center">
|
||||
|
|
Загрузка…
Ссылка в новой задаче