class BodyBlock(StreamBlock): h1 = CharBlock() h2 = CharBlock() paragraph = RichTextBlock() image_text = ImageText() image_carousel = ListBlock(CustomImageChooserBlock()) thumbnail_gallery = ListBlock(CustomImageChooserBlock())
class BodyBlock(StreamBlock): h1 = CharBlock() h2 = CharBlock() paragraph = RichTextBlock() markdown = MarkdownBlock(icon="code") image_text = ImageText() image_carousel = ListBlock(ImageChooserBlock()) thumbnail_gallery = ListBlock(ImageChooserBlock())
class BackersBlock(StructBlock): gold_backers = ListBlock(ImageBackerBlock()) silver_backers = ListBlock(ImageBackerBlock()) bronze_backers = ListBlock(ImageBackerBlock()) linked_backers = ListBlock(LinkedBackerBlock()) named_backers = ListBlock(NamedBackerBlock()) class Meta: template = "blog/blocks/backers.html"
class HeadingPanelStreamBlock(StreamBlock): quicklinks = ListBlock(QuickLinkBlock(), icon='link', label='Snarveis- panel', template='home/blocks/quicklink_list.html') imageslider = ListBlock(ImageSliderBlock(), icon='image', label='Bilde- karusell', template='home/blocks/imageslider_list.html') bannerimage = ImageBannerBlock( label='Bannerbilde.\nOBS: 2048x500 piksler!')
class ParallaxBlock(StructBlock): image = ImageChooserBlock() title = CharBlock(max_length=64) info_text = CharBlock(max_length=255) links = ListBlock(PageChooserBlock(), required=False) external_links = ListBlock(CustomURLBlock(), required=False) mail_links = ListBlock(CustomEmailLinkBlock(), required=False) class Meta: template = 'home/partials/blocks/parallax.html' icon = 'code'
class SidebarBlock(StructBlock): class Meta: template = "website/blocks/sidebar_block.html" h3 = CharBlock(icon="title", classname="title", label=_('heading'), template="website/blocks/h3.html") paragraph = RichTextBlock( icon="pilcrow", # editor = "simple", label=_('text')) image = ListBlock(ImageBlock( label=_('image'), icon='image', ), verbose_name=_('Bild'), default=[]) # image = ImageBlock( # label= _('image'), # icon= 'image', # required = False # ) paragraph2 = RichTextBlock( icon="pilcrow", # editor="simple", label=_('text'), required=False) link = LinkedPageBlock(label=_('internal link'), icon='doc-full-inverse')
class FAQListBlock(StructBlock): title = CharBlock(required=False, help_text='Title of your FAQ list (Optional)') content = ListBlock(FAQBlock()) class Meta: template = 'blocks/section.html'
class CarouselBlock(StructBlock): slides = ListBlock(SlideBlock) class Meta: template = "streams/carousel_block.html" icon = 'image' label = 'Carousel'
class TimelineBlock(BaseStructBlock): title = CharBlock() items = ListBlock(TimelineItemBlock()) class Meta: icon = 'list-ol' template = 'core/blocks/timeline_block.html'
class PageWithSidebar(Page): page_type = CharField(max_length=100, choices=PAGE_CHOICES, default='none') show_in_sitemap = BooleanField(default=True) reference_title = TextField(null=True, blank=True) subtitle = TextField(null=True, blank=True) menu_title = TextField(blank=True) is_nav_root = BooleanField(default=False) is_selectable = BooleanField(default=True) body = StreamField([('advertisement', AdvertisementInline()), ('paragraph', RichTextBlock()), ('image', ImageChooserBlock()), ('document', DocumentViewerBlock()), ('html', RawHTMLBlock()), ('audio', AudioBlock()), ('video', VideoPlayerBlock()), ('tabs', TabsBlock()), ('translations', ListBlock(StructBlock( [('word', RichTextBlock(required=True)), ('translation', RichTextBlock(required=True))]), template="blocks/transcriptions.html")), ('post', PostBlock()), ('choosen_reviews', ChoosenReviews())], blank=True) def get_nav_root(self) -> Page: return get_nav_root(self)
class SidePanelStreamBlock(StreamBlock): eventviewer = EventsBlock(label='Vis kommende aktiviteter') linkviewer = ListBlock(SidepanelLinkBlock(), icon='link', label='Lenke- fremviser', template='home/blocks/sidepanel_links.html') videoembed = VideoBlock(label='Youtube- video')
class CardBlock(StructBlock): """Карточки с изображением, текстом и кнопкой.""" title = CharBlock(required=True, help_text="Add your title") cards = ListBlock( StructBlock( [ ("image", ImageChooserBlock(required=True)), ("title", CharBlock(required=True, max_length=40)), ("text", TextBlock(required=True, max_length=200)), ("button_page", PageChooserBlock(required=False)), ( "button_url", URLBlock( required=False, help_text="Если выбрана страница кнопки выше, она будет использоваться первой.", # noqa ), ), ] ) ) class Meta: # noqa template = "layouts/card_block.html" icon = "placeholder" label = "Карточка с фото"
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 LinkListBlock(StructBlock): footer_links = ListBlock( StructBlock([ ('text', CharBlock()), ('page', PageChooserBlock()), ('external_link', URLBlock()), ]))
class PromoGroupBlock(FlattenValueContext, StructBlock): column = ChoiceBlock([ ('one-half', 'One-half'), ('one-third', 'One-third'), ], default='one-half', required=True) size = ChoiceBlock([ ('', 'Default'), ('small', 'Small'), ], required=False) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) context['num_columns'] = { 'one-half': 2, 'one-third': 3, }[value['column']] return context heading_level = IntegerBlock( min_value=2, max_value=6, default=3, help_text= 'The heading level affects users with screen readers. Default=3, Min=2, Max=6.' ) promos = ListBlock(BasePromoBlock) class Meta: template = 'wagtailnhsukfrontend/promo_group.html' help_text = 'This component is now deprecated and will be removed from future versions, please use the card group block'
class HeroBlock(StructBlock): image = ImageChooserBlock(required=False) title = CharBlock(required=True) subtitle = TextBlock(required=False) height = CharBlock(required=True, default='700px') container_alignment = ChoiceBlock(default='w3-display-middle', choices=[ ('w3-display-middle', 'Center'), ('w3-display-left container', 'Left'), ('w3-display-right container', 'Right'), ], blank=True, required=True) text_alignment = ChoiceBlock(default='w3-center', choices=[ ('w3-center', 'Center'), ('w3-left-align', 'Left'), ('w3-right-align', 'Right'), ], blank=True, required=True, editable=False) buttons = ListBlock(ButtonBlock) class Meta: template = "blocks/hero.html"
class ProtocolBlock(StructBlock): complete_pdf = DocumentChooserBlock(label='Complete PDF') pdfs = ListBlock(PDFBlock(), label='Chapter PDFs') image = ImageBlock() version = CharBlock() class Meta: icon = 'fa fa-newspaper-o' template = 'blocks/protocol_block.html' def get_context(self, value, parent_context=None): context = super(ProtocolBlock, self).get_context(value, parent_context=parent_context) context['links'] = [] for pdf in value.get('pdfs'): context['links'] += [{ 'fontawesome': 'file-pdf-o', 'href': pdf.get('file').url, 'text': pdf.get('description') }] try: rendition = value.get('image').get_rendition('max-500x500') context['image'] = { 'url': rendition.url, 'name': value.get('image').title } except: pass return context
class SupportersBlock(StructBlock): supporters = ListBlock(SupporterBlock) class Meta: icon = 'fa fa-male' template = 'blocks/supporters_block.html' def get_context(self, value, parent_context=None): context = super(SupportersBlock, self).get_context(value, parent_context=parent_context) context['supporters'] = [] for supporter in value.get('supporters'): supp_dict = { 'name': supporter.get('name'), 'text': supporter.get('content') } # for contact in supporter.get('contacts'): # n, w, e = contact.get('name'), contact.get('website'), contact.get('email') # supp_dict['text'] += "<p>{n} <a target='_blank' href='{w}'><i class='fa fa-external-link' aria-hidden='true'></i></a> " \ # "<a target='_blank' href='mailto:{e}'><i class='fa fa-envelope' aria-hidden='true'></i></a></p>".format(n=n, w=w, e=e) try: supp_dict['image'] = { 'url': supporter.get('image').get_rendition( 'fill-500x500-c100').url, 'name': supporter.get('image').title } except: pass context['supporters'] += [supp_dict] return context
class NestedPageGroup(StructBlock): """Class for a nested page group.""" class Meta: icon = 'list-ul' label = 'Page group' value_class = TransStructValue page = PageChooserBlock( help_text='Optional: top level page for the group', required=False, label='Top level page', ) title_en = CharBlock( help_text='Optional: plain text title for the page group', label='Title [en]', required=False, ) title_fr = CharBlock( help_text='Optional: plain text title for the page group', label='Title [fr]', required=False, ) page_group = ListBlock( TranslatedPage(), required=False, help_text='Optional: group of sub pages, displayed as an indented list', )
class IsiNumbersBlock(StructBlock): numbers = ListBlock(_IsiNumberBlock()) class Meta: icon = 'form' template = 'blocks/isi_numbers_block.html' def get_context(self, value, parent_context=None): context = super(IsiNumbersBlock, self).get_context(value, parent_context=parent_context) page = context['page'] if page.number1_imported_number and len( context['value']['numbers']) >= 1: context['value']['numbers'][0][ 'number'] = page.number1_imported_number if page.number2_imported_number and len( context['value']['numbers']) >= 2: context['value']['numbers'][1][ 'number'] = page.number2_imported_number if page.number3_imported_number and len( context['value']['numbers']) >= 3: context['value']['numbers'][2][ 'number'] = page.number3_imported_number if page.number4_imported_number and len( context['value']['numbers']) >= 4: context['value']['numbers'][3][ 'number'] = page.number4_imported_number return context
class CarouselBlock(StructBlock): image_items = ListBlock(ImageChooserBlock(required=True), label="Image Item") class Meta: icon = "image" template = "blocks/carousel_block.html"
class FeatureSectionBlock(SectionBlock): heading = CharBlock( required=False, max_length=100, label='Heading', default='Why our product is best', help_text='Add a heading at the beginning of this page section'), description = TextBlock( required=False, max_length=400, label='Description', help_text= 'This is the paragraph where you can write more details about your product. Keep it meaningful!' ) image = ImageChooserBlock( required=False, label='Image', help_text= 'Pick an image (e.g. of the product) for the side panel of a feature list' ) features = ListBlock(FeatureBlock(), label='Features') class Meta: icon = 'list-ul' label = 'Product Features Section'
class TestBlock(StreamBlock): field = SingleLineFormFieldBlock(icon='placeholder') p = CharBlock() special = TestStructBlock() list = ListBlock(SingleLineFormFieldBlock(label='Field')) stream = StreamBlock([('field', SingleLineFormFieldBlock()), ('p', CharBlock())])
class PeopleBlock(StructBlock): title = CharBlock(required=True) intro = RichTextBlock(required=True) people = ListBlock(PageChooserBlock()) class Meta: template = 'blocks/services/people_block.html'
class HighlightBlock(StructBlock): title = CharBlock(required=True) intro = RichTextBlock(required=False) highlights = ListBlock(TextBlock()) class Meta: template = 'blocks/services/highlight_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 ExpanderGroupBlock(FlattenValueContext, StructBlock): expanders = ListBlock(ExpanderBlock) class Meta: icon = 'plus-inverse' template = 'wagtailnhsukfrontend/expander_group.html'
class PapersBlock(StructBlock): see_all_offset = IntegerBlock(default=8, help_text='Show "See all" after x entries.') papers = ListBlock(PaperBlock) class Meta: icon = 'fa fa-file-text' template = 'blocks/outcomes_block.html'
class BaseStreamBlock(StreamBlock): heading_block = HeadingBlock() indented_paragraph_block = RichTextBlock( icon='pilcrow', template='blocks/indented_paragraph_block.html', features=['ol', 'ul', 'bold', 'italic', 'strikethrough', 'hr', 'link'], label='Indented Text') paragraph_block = RichTextBlock( icon='pilcrow', template='blocks/paragraph_block.html', features=['ol', 'ul', 'bold', 'italic', 'strikethrough', 'hr', 'link'], label='Text') image_block = ImageBlock() landscape_images_block = ListBlock( SimpleImageBlock(), label='Landscape Images', icon='image', template='blocks/landscape_images_block.html', help_text= 'Add even number of images (it inserts 2 horizontal images on the line)' ) portrait_images_block = ListBlock( SimpleImageBlock(), label='Portrait Images', icon='image', template='blocks/portrait_images_block.html', help_text='Add 2 images (it inserts 2 vertical images on the line)') image_slider_block = ListBlock( SliderImageBlock(), label='Image Slider', icon='image', template='blocks/image_slider_block.html', help_text='Full width image slider, add at least 4 images') block_quote = QuoteBlock() embed_block = EmbedBlock( help_text= 'Insert an embed URL e.g https://www.youtube.com/embed/SGJFWirQ3ks', icon='media', template='blocks/embed_block.html') raw_html = RawHTMLBlock( required=False, template='blocks/raw_html_block.html', label='Raw HTML', help_text= 'A text area for entering raw HTML which will be rendered unescaped') map_block = MapBlock()
class SummaryListBlock(FlattenValueContext, StructBlock): rows = ListBlock(SummaryListRowBlock) no_border = BooleanBlock(default=False, required=False) class Meta: icon = 'form' template = 'wagtailnhsukfrontend/summary_list.html'