class EscuelaVarillajeAboutLightBlock(StructBlock): nombre = CharBlock(classname="text-white mt-0", required=False) clase_css = ChoiceBlock(choices=[ ('bg-white', 'bg-white'), ('bg-transparent', 'bg-transparent'), ('bg-light', 'bg-light'), ]) titulo = CharBlock(classname="text-white mt-0", required=True) titulo_tipo = ChoiceBlock(choices=[ ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ]) intro = CharBlock(classname="text-white mt-0", required=False) intro_tipo = ChoiceBlock(choices=[ ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ], required=False) cuerpo = RichTextBlock(required=False) boton_texto = CharBlock(classname="text-white mt-0", required=False) boton_link = CharBlock(classname="text-white mt-0", required=False) class Meta: icon = "title" template = "escueladevarillaje/blocks/escuela_varillaje_about_light_block.html"
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 EscuelaVarillajeAboutColorBlock(StructBlock): nombre = CharBlock(classname="text-white mt-0", required=False) clase_css = ChoiceBlock(choices=[ ('', 'Seleccionar una clase'), ('bg-primary', 'bg-primary'), ('bg-secondary', 'bg-secondary'), ('bg-success', 'bg-success'), ('bg-info', 'bg-info'), ('bg-warning', 'bg-warning'), ('bg-danger', 'bg-danger'), ('bg-dark', 'bg-dark'), ]) titulo = CharBlock(classname="text-white mt-0", required=True) titulo_tipo = ChoiceBlock(choices=[ ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ]) intro = CharBlock(classname="text-white mt-0", required=False) intro_tipo = ChoiceBlock(choices=[ ('h2', 'H2'), ('h3', 'H3'), ('h4', 'H4'), ], required=False) cuerpo = RichTextBlock(required=False) boton_texto = CharBlock(classname="text-white mt-0", required=False) boton_link = CharBlock(classname="text-white mt-0", required=False) class Meta: icon = "title" template = "escueladevarillaje/blocks/escuela_varillaje_about_color_block.html"
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 BootstrapButton(StructBlock): """ Custom 'StructBlock' that allows the user to make a bootstrap button """ button_text = TextBlock() button_link = TextBlock() button_color = ChoiceBlock(choices=[('btn-primary', 'DEFAULT'), ('btn-danger', 'RED'), ('btn-secondary', 'GREY'), ('btn-success', 'GREEN'), ('btn-warning', 'ORANGE')], blank=True, required=False, help_text="select a button color") button_size = ChoiceBlock(choices=[('', 'DEFAULT'), ('btn-lg', 'LARGE'), ('btn-sm', 'SMALL')], blank=True, required=False, help_text="select a button size") 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-bold" template = "blocks/bootstrap/button.html" help_text = "Create a bootstrap button"
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 IdeaCarouselBlock(StructBlock): headline = CharBlock(required=False) year = ProjectChooserBlock(required=False) field_of_action = ChoiceBlock(choices=idea_section.FIELD_OF_ACTION_CHOICES, required=False) ordering = ChoiceBlock(choices=filters.ORDERING_CHOICES, required=False) status = ChoiceBlock(choices=filters.STATUS_FILTER_CHOICES, required=False) class Meta: template = 'cms_home/blocks/carousel_block.html' icon = 'folder-inverse' label = 'Carousel Block' help_text = 'Displays up to 20 ideas that match the filters'
class BaseImageBlock(StructBlock): image = ImageChooserBlock(required=True) caption = CharBlock(required=False) size = CharBlock( label=_('Image resize'), required=False, help_text=_( 'It must be defined in wagtail picture redimension tag: width-640, height-480, ' 'fill-200x200-c100 or original (which is the default option)')) alignment = ChoiceBlock(choices=IMG_ALIGN_CHOICES, default=" ") shape = ChoiceBlock(choices=IMG_CLASS_CHOICES, default=" ") class Meta: icon = 'image' template = "blocks/block_image.html"
class CodeBlock(StructBlock): """ Code Highlighting Block """ LANGUAGE_CHOICES = ( ('bash', 'Bash/Shell'), ('css', 'CSS'), ('django', 'Django templating language'), ('html', 'HTML'), ('javascript', 'Javascript'), ('python', 'Python'), ('scss', 'SCSS'), ) language = ChoiceBlock(choices=LANGUAGE_CHOICES) code = TextBlock() class Meta: icon = 'code' def render(self, value): src = value['code'].strip('\n') lang = value['language'] lexer = get_lexer_by_name(lang) formatter = get_formatter_by_name( 'html', linenos=None, cssclass='codehilite', style='default', noclasses=False, ) return mark_safe(highlight(src, lexer, formatter))
class CodeBlock(StructBlock): language = ChoiceBlock(choices=LANGUAGES, blank=False, null=False, default='python') caption = CharBlock(required=False, blank=True, nullable=True) code = TextBlock() class Meta: icon = "code" def render(self, value, *args, **kwargs): src = value['code'].strip('\n') caption = value['caption'].strip() lang = value['language'] lexer = get_lexer_by_name(lang) formatter = get_formatter_by_name( 'html', linenos=None, cssclass='codehilite', style='github', noclasses=False, ) render_content = highlight(src, lexer, formatter) if caption: caption_content = '<div class="code-caption">{}</div>\n'.format( caption) render_content = caption_content + render_content return mark_safe(render_content)
class EscuelaVarillajeUbicacionColorBlock(StructBlock): nombre = CharBlock(classname="text-white mt-0", required=False) clase_css = ChoiceBlock(choices=[ ('', 'Seleccionar una clase'), ('bg-primary', 'bg-primary'), ('bg-secondary', 'bg-secondary'), ('bg-success', 'bg-success'), ('bg-info', 'bg-info'), ('bg-warning', 'bg-warning'), ('bg-danger', 'bg-danger'), ('bg-dark', 'bg-dark'), ]) titulo = CharBlock(classname="text-white mt-0", required=False) cuerpo = RichTextBlock(required=False) telefono = blocks.CharBlock(max_length=22) calle = blocks.CharBlock(max_length=255) colonia = blocks.CharBlock(max_length=255) ciudad = blocks.CharBlock(max_length=255) estado = blocks.CharBlock(max_length=255) facebook_url = blocks.URLBlock() youtube_url = blocks.URLBlock() instagram_url = blocks.URLBlock() email = blocks.EmailBlock() class Meta: template = 'escueladevarillaje/blocks/escuela_varillaje_ubicacion_color_block.html' icon = "fa-globe"
class RowBlock(StreamBlock): distribution = ChoiceBlock( blank=False, choices=( ('left', 'left side bigger'), ('right', 'right side bigger'), ('equal', 'equal size sides'), ), min_num=1, max_num=1, ) paragraph = RichTextBlock( features=settings.RICHTEXT_ADVANCED, template="categories/blocks/paragraph.html", icon="pilcrow", ) linked_image = LinkedImageBlock() card = CardBlock() pullquote = PullQuoteBlock() # questionable that this should be advanced HTML but we use callouts a lot snippet = RichTextBlock( features=settings.RICHTEXT_ADVANCED, label="Callout", template="categories/blocks/snippet.html") class Meta: help_text = "Use a 'distribution' block to choose how the row's columns are balanced." icon = 'grip' template = "categories/blocks/row.html"
class D3OptionsMixin(models.Model): class Meta: abstract = True D3_MODULES = [ ('colour', 'Colour'), ('interpolate', 'Interpolate'), ('scale-chromatic', 'Scale Chromatic'), ] D3_VERSIONS = [ ('v4', 'Version 4'), ('v5', 'Version 5'), ('v6', 'Version 6'), ] use_d3 = models.BooleanField(default=False, blank=True, verbose_name='Use D3') d3_version = models.CharField(default='v4', max_length=50, choices=D3_VERSIONS, verbose_name='D3 Version') d3_modules = StreamField( [('module', ChoiceBlock(label='Module', choices=D3_MODULES))], blank=True, verbose_name='D3 Modules')
def __init__(self, local_blocks=None, **kwargs): # Languages included in PrismJS core # Review: https://github.com/PrismJS/prism/blob/gh-pages/prism.js#L602 self.INCLUDED_LANGUAGES = ( ('html', 'HTML'), ('mathml', 'MathML'), ('svg', 'SVG'), ('xml', 'XML'), ) if local_blocks is None: local_blocks = [] else: local_blocks = local_blocks.copy() language_choices, language_default = self.get_language_choice_list( **kwargs) local_blocks.extend([ ('language', ChoiceBlock( choices=language_choices, help_text=_('Coding language'), label=_('Language'), default=language_default, identifier='language', )), ('code', TextBlock(label=_('Code'), identifier='code')), ]) super().__init__(local_blocks, **kwargs)
class TextEditorBlock(StructBlock): alignment = ChoiceBlock( [("left", "Left"), ("center", "Center"), ("right", "Right"), ("justify", "Justify")], blank=False, required=True, ) paragraph_text = RichTextBlock( icon="fa-paragraph", features=[ "h1", "h2", "h3", "h4", "h5", "h6", "bold", "u" "italic", "hr", "ol", "ul", "link", "document-link", ], ) class Meta: icon = "fa-quote-left" template = "blocks/paragraph_block.html"
class EscuelaVarillajeThreeIconColumnColorBlock(StructBlock): nombre = CharBlock(required=False) clase_css = ChoiceBlock(choices=[ ('', 'Seleccionar una clase'), ('bg-primary', 'bg-primary'), ('bg-secondary', 'bg-secondary'), ('bg-success', 'bg-success'), ('bg-info', 'bg-info'), ('bg-warning', 'bg-warning'), ('bg-danger', 'bg-danger'), ('bg-dark', 'bg-dark'), ]) titulo = CharBlock(required=False) left_column = EscuelaVarillajeIconColumnColorBlock(icon='placeholder', label='Izquierda') center_column = EscuelaVarillajeIconColumnColorBlock(icon='placeholder', label='Centro') right_column = EscuelaVarillajeIconColumnColorBlock(icon='placeholder', label='Derecha') boton_texto = CharBlock(required=False) boton_link = CharBlock(required=False) class Meta: template = 'escueladevarillaje/blocks/escuela_varillaje_three_icon_column_color_block.html' icon = 'group' label = 'Tres columnas ícono color'
class CareCardBlock(FlattenValueContext, StructBlock): type = ChoiceBlock([ ('primary', 'Non-urgent'), ('urgent', 'Urgent'), ('immediate', 'Immediate'), ], required=True, default='primary',) heading_level = IntegerBlock(required=True, min_value=2, max_value=4, default=3, help_text='The heading level affects users with screen readers. Default=3, Min=2, Max=4.') title = CharBlock(required=True) class BodyStreamBlock(StreamBlock): richtext = RichTextBlock() action_link = ActionLinkBlock() details = DetailsBlock() inset_text = InsetTextBlock() image = ImageBlock() grey_panel = GreyPanelBlock() warning_callout = WarningCalloutBlock() summary_list = SummaryListBlock() body = BodyStreamBlock(required=True) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) context['accessible_title_prefix'] = { 'primary': 'Non-urgent advice: ', 'urgent': 'Urgent advice:', 'immediate': 'Immediate action required:', }[value['type']] return context class Meta: icon = 'help' template = 'wagtailnhsukfrontend/care_card.html'
class CareCardBlock(FlattenValueContext, StructBlock): type = ChoiceBlock( [ ('primary', 'Non-urgent'), ('urgent', 'Urgent'), ('immediate', 'Immediate'), ], required=True, default='primary', ) heading_level = IntegerBlock( required=True, min_value=2, max_value=4, default=3, help_text= 'The heading level affects users with screen readers. Default=3, Min=2, Max=4.' ) title = CharBlock(required=True) body = RichTextBlock(required=True) def get_context(self, value, parent_context=None): context = super().get_context(value, parent_context) context['accessible_title_prefix'] = { 'primary': 'Non-urgent advice: ', 'urgent': 'Urgent advice:', 'immediate': 'Immediate action required:', }[value['type']] return context class Meta: template = 'wagtailnhsukfrontend/care_card.html'
class CodeBlock(StructBlock): """ Code Highlighting Block """ LANGUAGE_CHOICES = ( ("bash", "Bash/Shell"), ("css", "CSS"), ("django", "Django templating language"), ("html", "HTML"), ("javascript", "Javascript"), ("python", "Python"), ("scss", "SCSS"), ) language = ChoiceBlock(choices=LANGUAGE_CHOICES) code = TextBlock() class Meta: icon = "code" template = None def render_basic(self, value, context=None): src = value["code"].strip("\n") lang = value["language"] lexer = get_lexer_by_name(lang) formatter = get_formatter_by_name( "html", linenos=None, cssclass="codehilite", style="default", noclasses=False, ) return mark_safe(highlight(src, lexer, formatter))
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 RowBlock(StructBlock): """ Define the blocks that all rows will utilize """ background = ImageChooserBlock( required=False, help_text="This will set the background image of the row.", group="Container") padding = ChoiceBlock( choices=[ ('', 'Select a padding size'), ('none', 'None'), ('small', 'Small'), ('medium', 'Medium'), ('large', 'Large'), ], blank=True, required=False, help_text= "Select how much top and bottom padding you would like on the row.", group="Container") content = StreamBlock([ ('column', ColumnBlock()), ], help_text="Add column to row.") class Meta: icon = "fa-align-justify" template = "blocks/row.html" closed = True
class CodeBlock(StructBlock): """ Code Highlighting Block """ LANGUAGE_CHOICES = ( ("python", "Python"), ("cpp", "C++"), ("html", "HTML"), ("css", "CSS"), ) language = ChoiceBlock(choices=LANGUAGE_CHOICES) code_text = TextBlock() def render(self, value): src = value["code_text"].strip("\n") lang = value["language"] lexer = get_lexer_by_name(lang) formatter = get_formatter_by_name("html", linenos="table", noclasses=True, style="monokai") return mark_safe(highlight(src, lexer, formatter))
class Plain(Page): footer_colour = models.CharField("Hover colour", max_length=255, blank=True, null=True) plain_text = RichTextField(blank=True) page_content = StreamField([ ('text_block', StructBlock([ ('text', RichTextBlock(blank=True)), ('width', ChoiceBlock(required=False, max_length=20, choices=( (u'6', u'half'), (u'8', u'third'), ))), ], template='home/blocks/text.html', icon="pilcrow")), ], blank=True) content_panels = Page.content_panels + [ FieldPanel('plain_text'), StreamFieldPanel('page_content'), ] promote_panels = [ FieldPanel('footer_colour'), ] + Page.promote_panels
class TestimonialBlock(StructBlock): name = CharBlock(required=True, max_length=100, label='Name', help_text='Name of the person making the recommendation'), role = CharBlock( required=False, max_length=100, label='Role', help_text='Job title of the person making the recommentation, if any'), organisation = CharBlock( required=False, max_length=100, label='Organisation', help_text='Name of the organisation the person is part of, if any'), quote = TextBlock(required=True, max_length=100, label='Quote', help_text='The nice things they have to say') image = ImageChooserBlock( required=False, label='Logo/Picture', help_text="Add either a company logo or a person's mugshot") stars = ChoiceBlock(required=True, choices=[(None, 'No rating'), (0, '0 Stars'), (1, '1 Star'), (2, '2 Stars'), (3, '3 Stars'), (4, '4 Stars'), (5, '5 Stars')], icon='pick') class Meta: icon = 'pick' label = 'Testimonial'
class CaptionedImageBlock(StructBlock): """ An image block with a caption, credit, and alignment. """ image = ImageChooserBlock(help_text='The image to display.', ) caption = TextBlock( required=False, help_text='The caption will appear under the image, if entered.') credit = TextBlock( required=False, help_text='The credit will appear under the image, if entered.') align = ChoiceBlock( choices=[ ('left', 'Left'), ('right', 'Right'), ('center', 'Center'), ('full', 'Full Width'), ], default='left', help_text='How to align the image in the body of the page.') class Meta: icon = 'image' template = 'wagtailcontentstream/blocks/captioned_image.html' help_text = 'Select an image and add a caption (optional).'
class IconBlock(StructBlock): position = ChoiceBlock(choices=(('left', 'Left'), ('center', 'Center'), ('right', 'Right')), default='center') icon = TextBlock("") icon_colour = TextBlock("") content = RichTextBlock("")
class CardFeatureBlock(FlattenValueContext, StructBlock): feature_heading = CharBlock(required=True) heading_level = IntegerBlock( min_value=2, max_value=6, default=3, help_text= 'The heading level affects users with screen readers. Ignore this if there is no label. Default=3, Min=2, Max=6.' ) heading_size = ChoiceBlock( [ ('', 'Default'), ('small', 'Small'), ('medium', 'Medium'), ('large', 'Large'), ], help_text= 'The heading size affects the visual size, this follows the front-end library\'s sizing.', required=False) body = RichTextBlock(required=True) class Meta: label = 'Feature card' icon = 'doc-full' template = 'wagtailnhsukfrontend/card.html'
class BootstrapWell(StructBlock): """ Custom 'StructBlock' that allows user to make a bootstrap well. (optimized for bootstrap 4 using card) """ message = RichTextBlock(help_text="Enter some message inside well") well_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") 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-window-minimize" template = "blocks/bootstrap/well.html"
class CalloutBlock(StructBlock): value = TextBlock() variant = ChoiceBlock(label='Variant', choices=( ('info', 'Info'), ('warning', 'Warning'), ('alert', 'Alert'), ))
class MenuTypeChoiceBlock(StructBlock): menu_item_choice = ChoiceBlock(choices=MENU_TYPE_CHOICES, blank=False, required=True) class Meta: icon = 'fa-signs' template = "wagtailrestaurantmenus/menu_type_block.html"