class BootstrapCard(StructBlock): """ Custom 'StructBlock' that allows the user to make a bootstrap card """ card_width = IntegerBlock(help_text="18 works best for card", required=False, blank=True) is_card_img = BooleanBlock(required=False) is_card_img_overlay = BooleanBlock( required=False, default=False, help_text="Use image as background for card", label="Image Overlay?") card_img = ImageChooserBlock(required=False) card_img_width = IntegerBlock(required=False, help_text="provide an image width") card_img_height = IntegerBlock(required=False, help_text="provide an image height") card_title = TextBlock(required=False, null=True, blank=True) card_text = RichTextBlock(required=False, null=True, blank=True) card_bg_color = ChoiceBlock(choices=[ ('bg-primary', 'DEFAULT'), ('bg-secondary', 'GREY'), ('bg-success', 'GREEN'), ('bg-danger', 'RED'), ('bg-warning', 'ORANGE'), ('bg-dark', 'DARK'), ('bg-light', 'LIGHT'), ], blank=True, required=False, help_text="select a background color") card_text_color = ChoiceBlock(choices=[ ('text-primary', 'DEFAULT'), ('text-secondary', 'GREY'), ('text-success', 'GREEN'), ('text-danger', 'RED'), ('text-warning', 'ORANGE'), ('text-dark', 'DARK'), ('text-light', 'LIGHT'), ], blank=True, required=False, help_text="select a text color") buttons = ListBlock(BootstrapButton(required=False), default=[]) custom_class = TextBlock( required=False, blank=True, help_text="control this element by giving unique class names " "separated by space and styling the class in css") class Meta: icon = "fa-id-card" template = "blocks/bootstrap/card.html" help_text = "Create a bootstrap card"
class PhotoSlider(StructBlock): image_height = IntegerBlock(min_value=0, max_value=2000, default=64) image_width = IntegerBlock(min_value=0, max_value=2000, default=260) crop_to_fit = BooleanBlock(default=False, required=False) random_order = BooleanBlock(default=False, required=False) photos = ListBlock(PhotoGalleryItem()) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) return _get_gallery_context(context, value) class Meta: template = 'common/blocks/photo_slider_block.html'
class GroupToggleBlock(FormFieldBlock): required = BooleanBlock(label=_('Required'), default=True) choices = ListBlock( CharBlock(label=_('Choice')), help_text=('Please create only two choices for toggle. ' 'First choice will revel the group and the second hide it. ' 'Additional choices will be ignored.')) field_class = forms.ChoiceField widget = forms.RadioSelect class Meta: label = _('Group fields') icon = 'group' help_text = 'Remember to end group using Group fields end block.' def get_field_kwargs(self, struct_value): kwargs = super().get_field_kwargs(struct_value) field_choices = [(choice, choice) for choice in struct_value['choices']] total_choices = len(field_choices) if total_choices > 2: # For toggle we need only two choices field_choices = field_choices[:2] elif total_choices < 2: field_choices = [ ('yes', 'Yes'), ('no', 'No'), ] kwargs['choices'] = field_choices return kwargs
class FocusItem(AbstractHighlight): """Class to define the focus item in a navigation menu.""" class Meta: help_text = ''' <strong>Focus item module</strong><br> Internal page link, short description, and link label.<br> Optional: external url for secondary link, display secondary link as button. ''' icon = 'pick' template = 'navigation/blocks/focus_item.html' external_url = URLBlock( help_text= 'Optional: external URL for the secondary link. Defaults to the selected page link', required=False, ) link_label_en = CharBlock( help_text='Label for the secondary page link', label='Link label [en]', ) link_label_fr = CharBlock( help_text='Label for the secondary page link', label='Link label [fr]', required=False, ) use_button_style = BooleanBlock( help_text= 'Optional: if checked, the secondary link will display as a button', required=False, )
class ButtonBlock(StructBlock): button_text = CharBlock(required=True) link = CharBlock(required=True) flat_button = BooleanBlock(required=False, default=False) class Meta: template = 'website/blocks/button_block.html'
class CheckboxFormFieldBlock(FormFieldBlockMixin, StructBlock): default_checked = BooleanBlock(default=False, required=False) class Meta: label = 'Checkbox Field' icon = 'tick-inverse' def get_field_options(self, field): options = super(CheckboxFormFieldBlock, self).get_field_options(field) options['initial'] = field['default_checked'] return options def create_field(self, field): options = self.get_field_options(field) return django.forms.BooleanField(**options) def render_basic(self, value, context=None): if context: form = context['form'] else: form = { self.clean_name(value): self.create_field(value) } return format_html( '<div class="{}">{}{}</div>', self.__class__.__name__.lower(), form[self.clean_name(value)], form[self.clean_name(value)].label_tag() )
class SectionParagraphBlock(StructBlock): text = RichTextBlock(features=RICHTEXT_FEATURES_NO_FOOTNOTES) center = BooleanBlock(default=False, required=False) class Meta(): icon = 'fa-paragraph' template = 'blocks/section_paragraph_block.html'
class BootstrapAlert(StructBlock): """ Custom 'StructBlock' that allows the user to make a bootstrap alert """ alert_text = TextBlock() alert_color = ChoiceBlock(choices=[ ('alert-primary', 'DEFAULT'), ('alert-secondary', 'GREY'), ('alert-success', 'GREEN'), ('alert-danger', 'RED'), ('alert-warning', 'ORANGE'), ('alert-dark', 'DARK'), ('alert-light', 'LIGHT'), ], blank=True, required=False, help_text="select a background color") is_link = BooleanBlock(required=False) alert_link = TextBlock(required=False) custom_class = TextBlock( required=False, blank=True, help_text="control this element by giving unique class names " "separated by space and styling the class in css") class Meta: icon = "fa-bell" template = "blocks/bootstrap/alert.html" help_text = "Create a bootstrap alert"
class ExpertiseBlock(StructBlock): """ Renders the 'our expertise' section """ heading = CharBlock(icon='fa-heading', required=False, default='Our expertise') description = RichTextBlock(icon='fa-paragraph', template='blocks/paragraph_block.html', features=RICHTEXT_FEATURES_NO_FOOTNOTES, required=False) expertise_list = ListBlock(StructBlock([ ('name', TextBlock(icon='fa-text')), ('description', RichTextBlock(icon='fa-paragraph', template='blocks/paragraph_block.html', features=RICHTEXT_FEATURES_NO_FOOTNOTES, required=False)) ]), required=False) light = BooleanBlock( default=False, required=False, help_text='Applies a lighter background to the section') class Meta(): template = 'blocks/expertise.html'
class AdvertisementInline(StructBlock): advertisement = SnippetChooserBlock(InlineAdvertisementSnippet) disable = BooleanBlock(required=False) class Meta: icon = 'snippet' label = 'Advert' template = 'blocks/advertisement_inline.html'
class ImageBlock(StructBlock): image = ImageChooserBlock() description = CharBlock(required=False) is_circle = BooleanBlock(label="Show as a circle?", required=False) is_full_width = BooleanBlock(required=False) content = StreamBlock([ ('testimonial', TestimonialBlock(target_model='pages.Testimonial', template='blocks/testimonial_block.html')), ('rich_text', RichTextBlock()), ], required=False) class Meta: label = 'Image' template = 'blocks/image_block.html' icon = 'fa-image'
class FullBleedImageBlock(StructBlock): image = ImageChooserBlock() caption = CharBlock(required=False) add_parallax = BooleanBlock() class Meta: icon = 'image' template = 'blog/blocks/full_bleed_image.html'
class ActionLinkBlock(FlattenValueContext, StructBlock): text = CharBlock(label="Link text", required=True) external_url = URLBlock(label="URL", required=True) new_window = BooleanBlock(required=False, label="Open in new window") class Meta: template = 'wagtailnhsukfrontend/action_link.html'
class CheckboxFieldBlock(FormFieldBlock): default_value = BooleanBlock(required=False) field_class = forms.BooleanField class Meta: label = _('Checkbox field') icon = 'tick-inverse'
class SummaryListBlock(FlattenValueContext, StructBlock): rows = ListBlock(SummaryListRowBlock) no_border = BooleanBlock(default=False, required=False) class Meta: icon = 'form' template = 'wagtailnhsukfrontend/summary_list.html'
class IconHeaderBlock(StructBlock): headline = TextBlock(help_text='Write a title for this section.') icon = IconBlock(help_text='Optional icon', required=False) visible = BooleanBlock(default=True, required=False) class Meta: icon = 'fa-header' template = 'blocks/icon_banner_header.html' help_text = 'A red banner headline with optional icon'
class EmbedContentBlock(StructBlock): embed = EmbedBlock(label="url", required=True) caption = CharBlock(label="caption", help_text="Enter a caption") use_as_hero = BooleanBlock(label="hero", help_text="Use as hero image", required=False) class Meta: icon = 'site' value_class = EmbedContentStructValue template = 'blocks/embed_block.html'
class BigTeaserBlock(StructBlock): title = CharBlock(required=True) subtitle = CharBlock(required=False) picture = ImageChooserBlock(required=False) full_width_picture = BooleanBlock(required=False, default=False) text = RichTextBlock(required=False) external_link = URLBlock( required=False, help_text="Will be ignored if an internal link is provided") internal_link = PageChooserBlock( required=False, help_text='If set, this has precedence over the external link.') from_date = DateBlock(required=False) to_date = DateBlock(required=False) class Meta: icon = 'fa fa-list-alt' template = 'blocks/big_teaser_block.html' def __init__(self, wideimage=False, local_blocks=None, **kwargs): super().__init__(local_blocks=local_blocks, **kwargs) self.wideimage = wideimage def get_context(self, value, parent_context=None): context = super(BigTeaserBlock, self).get_context(value, parent_context=parent_context) context['super_title'] = value.get('title') image = value.get('picture') if image: rendition = image.get_rendition('max-800x800') context['image'] = {'url': rendition.url, 'name': image.title} if value.get('internal_link'): context['href'] = value.get('internal_link').url else: context['href'] = value.get('external_link') if context['href']: context['text_right_link'] = True context['text_right_link_text'] = 'Learn more' context.update({ 'title': value.get('subtitle'), 'description': value.get('text'), 'divider': value.get('subtitle') and value.get('text'), 'calendaricon': True, 'full_width_picture': value.get('full_width_picture'), }) if value.get('from_date') and value.get('to_date'): context['date'] = '"{} to {}"'.format( formats.date_format(value.get('from_date'), "SHORT_DATE_FORMAT"), formats.date_format(value.get('to_date'), "SHORT_DATE_FORMAT")) context['wideimage'] = self.wideimage return context
class EventsBlock(StructBlock): count = UpcomingEventCountChoiceField(label='Antall synlige aktiviteter') centre_code = UpcomingEventCentreChoiceField(label='Hvilket senter?') display_all = BooleanBlock(label='Langtidsvisning', required=False) class Meta: icon = 'date' template = 'gcal/blocks/display_events.html' help_text = ( 'Ved å aktivere dette valget vil kommende aktiviteter vises.')
class SectionBlockQuote(StructBlock): """ Custom `StructBlock` that allows render text in a blockquote element """ text = TextBlock() source = TextBlock(required=False, help_text='Who is this quote acredited to?') center = BooleanBlock(default=False, required=False) class Meta: icon = 'fa-quote-right' template = 'blocks/section_blockquote.html'
class BootstrapAlertBlock(BootstrapBackground): title = CharBlock(required=False) content = RichTextBlock(features=[ 'p', ]) dismissable = BooleanBlock(required=False) class Meta: icon = 'fa-exclamation-triangle' template = 'global_utils/bootstrap_comonent_blocks/alert.html' form_classname = 'struct-block'
class ParallaxBlock(blocks.StructBlock): video = DocumentChooserBlock(required=True, icon='media') poster_image = APIImageChooserBlock(required=True, icon='image') focus = BooleanBlock( required=False, help_text=_('Auto focus to parallax on page load'), ) class Meta: template = 'blocks/parallax_block.html' icon = 'arrows-up-down' label = 'Parallax Video'
class TestimonialBlock(StructBlock): test_name = TextBlock(blank=True) test_quote = TextBlock(blank=True) test_pic = ImageChooserBlock(blank=True, required=False) test_reversed = BooleanBlock(required=False, default=False) panels = [FieldPanel('intro')] class Meta: template = "streams/testimonial_block.html" icon = 'group' label = 'Client Testimonial'
class ImageBlock(StructBlock): image = ImageChooserBlock(required=True) description = CharBlock(required=True) show_caption = BooleanBlock(required=False, default=False) # text = StreamBlock([ # ("string", StringBlock()), # ]) class Meta: template = "flexible/blocks/image_block.html" icon = "image" label = "Image Block"
class BaseStructBlock(StructBlock): show_in_menus = BooleanBlock(default=True, required=False) def get_form_context(self, value, prefix='', errors=None): context = super().get_form_context(value, prefix=prefix, errors=errors) fields = context['children'].copy() for field in reversed(context['children']): fields.move_to_end(field) context['children'] = fields return context
class CheckboxFieldBlock(OptionalFormFieldBlock): default_value = BooleanBlock(required=False) field_class = forms.BooleanField class Meta: label = _('Checkbox field') icon = 'tick-inverse' def get_searchable_content(self, value, data): return None def no_response(self): return False
class ImageBlock(StructBlock): """ Custom `StructBlock` for utilizing images with associated caption and attribution data """ image = ImageChooserBlock(required=True, label="Изображение") caption = CharBlock(required=False, label='Описание') attribution = CharBlock(required=False, label='др. аттрибуты') main = BooleanBlock(required=False, label='показывать первым') class Meta: icon = 'image' template = "blocks/image_block.html" form_classname = 'Изображение'
class HomepageBannerBlock(StructBlock): """ A HomepageBannerBlock presents the content of the 'homepage hero' widget. """ image = ImageChooserBlock(required=True) photo_credit = CharBlock(required=False) title = CharBlock(required=True) summary = TextBlock(required=True) url = LinkBlock() is_emergency = BooleanBlock(required=False) class Meta: template = "includes/blocks/homepage_banner_block.html"
class ImageDuoTextBlock(ImageBlock): heading = CharBlock(icon='fa-heading', required=False) side_text = RichTextBlock( icon='fa-paragraph', features=RICHTEXT_FEATURES_NO_FOOTNOTES, template='blocks/paragraph_block.html', required=True ) button = ButtonBlock() alt = BooleanBlock(default=False, help_text="White background if checked.", required=False) class Meta: template = 'blocks/duo_body_block_img.html' icon = 'fa-image'
class ImageBlock(StructBlock): """ Custom `StructBlock` for utilizing images with associated caption and attribution data """ image = ImageChooserBlock(required=True) caption = CharBlock(required=False) attribution = CharBlock(required=False) alignment = AlignmentBlock(default='left', required=False) border = BooleanBlock(required=False, help_text='Adds border around image') class Meta: icon = 'image' template = 'blocks/image_block.html'