class CallToActionBlock(blocks.StructBlock):
    content = blocks.RichTextBlock(required=False)
    link_text = blocks.CharBlock(help_text="Text that appears in the button")
    url = blocks.URLBlock()
    background_colour = blocks.ChoiceBlock(
        choices=[
            ('white', 'White'),
            ('primary', 'Primary'),
            ('success', 'Success'),
            ('info', 'Info'),
            ('warning', 'Warning'),
            ('danger', 'Danger'),
            ('inverse', 'Black'),
        ],
        default='white',
        help_text="The background colour of this section")
    button_colour = blocks.ChoiceBlock(
        choices=[
            ('primary', 'Primary'),
            ('secondary', 'Secondary'),
            ('success', 'Success'),
            ('info', 'Info'),
            ('warning', 'Warning'),
            ('danger', 'Danger'),
        ],
        default='pimary',
    )

    class Meta:
        template = 'blocks/call_to_action_block.html'
Beispiel #2
0
class ImageBlock(blocks.StructBlock):
    """
    A block for images whose layout properties and size can be set to one of
    a small number of useful values.
    """
    image = ImageChooserBlock()
    size = blocks.ChoiceBlock(choices=[
        ('tiny', 'Tiny'),
        ('small', 'Small'),
        ('medium', 'Medium'),
        ('large', 'Large'),
        ('full_width', 'Full Width'),
    ],
                              default='medium',
                              required=True)
    layout = blocks.ChoiceBlock(choices=[
        ('img-inline', 'Inline'),
        ('img-block', 'Block'),
        ('img-left', 'Float Left'),
        ('img-right', 'Float Right'),
        ('img-center', 'Center'),
    ],
                                default='inline',
                                required=True)

    class Meta:
        template = 'revolv_cms/blocks/image_block.html'
Beispiel #3
0
class BasicContentBlock(blocks.StructBlock):
    class Meta:
        template = "cms_pages/home_page_blocks/basic_content.html"

    PANEL_BLUE_LEFT = "blue_left"
    PANEL_WHITE_RIGHT = "white_right"
    PANEL_TYPES = (
        (PANEL_BLUE_LEFT, "Left-aligned image, blue-filtered image BG"),
        (PANEL_WHITE_RIGHT, "Right-aligned image, white background"),
    )

    panel_type = blocks.ChoiceBlock(
        choices=PANEL_TYPES,
        required=True,
    )
    heading = blocks.CharBlock(required=True)
    inset_illustration = blocks.ChoiceBlock(
        choices=ILLUSTRATION_TYPES,
        required=True,
    )
    background_image = imageblocks.ImageChooserBlock(
        required=False,
        help_text="This is used as the background image of a "
        "blue-left block. It's not used for white-right.")
    body = blocks.RichTextBlock(required=True)
    link = BasicContentLink()
    external_links = blocks.ListBlock(ExternalLinksBlock)
    compact = blocks.BooleanBlock(
        required=False,
        help_text="True if this block is to be displayed in 'compact' mode",
    )
Beispiel #4
0
class FilterControls(molecules.BaseExpandable):
    form_type = blocks.ChoiceBlock(choices=[
        ('filterable-list', 'Filterable List'),
        ('pdf-generator', 'PDF Generator'),
    ],
                                   default='filterable-list')
    title = blocks.BooleanBlock(default=True,
                                required=False,
                                label='Filter Title')
    post_date_description = blocks.CharBlock(default='Published')
    categories = blocks.StructBlock([
        ('filter_category', blocks.BooleanBlock(default=True, required=False)),
        ('show_preview_categories',
         blocks.BooleanBlock(default=True, required=False)),
        ('page_type', blocks.ChoiceBlock(choices=ref.page_types,
                                         required=False)),
    ])
    topics = blocks.BooleanBlock(default=True,
                                 required=False,
                                 label='Filter Topics')
    authors = blocks.BooleanBlock(default=True,
                                  required=False,
                                  label='Filter Authors')
    date_range = blocks.BooleanBlock(default=True,
                                     required=False,
                                     label='Filter Date Range')

    class Meta:
        label = 'Filter Controls'
        icon = 'form'

    class Media:
        js = [
            'notification.js', 'expandable.js', 'filterable-list-controls.js'
        ]
Beispiel #5
0
class GoogleCalendarBlock(blocks.StructBlock):
    calendars = blocks.ListBlock(
        blocks.StructBlock([
            ('source',
             blocks.CharBlock(
                 help_text=_('Calendar ID as given by google calendar'), )),
            ('color', ColorBlock()),
        ]))
    mode = blocks.ChoiceBlock(choices=[
        ('WEEK', _('Week')),
        ('', _('Month')),
        ('AGENDA', _('Agenda')),
    ],
                              required=False)
    height = blocks.IntegerBlock()
    background_color = ColorBlock()
    week_start = blocks.ChoiceBlock(choices=[
        ('2', _('Monday')),
        ('1', _('Sunday')),
        ('7', _('Saturday')),
    ])

    class Meta:
        label = _('Google Calendar')
        icon = 'fa-calendar'
        template = 'google/blocks/calendar.html'
        group = _('Embed')
Beispiel #6
0
class ChartBlock(blocks.StructBlock):
    title = blocks.CharBlock(required=True)
    # todo: make radio buttons
    chart_type = blocks.ChoiceBlock(choices=[
        ('bar', 'Bar'),
        ('line', 'Line'),
        ('tile_map', 'Tile Map'),
    ], required=True)
    color_scheme = blocks.ChoiceBlock(
        choices=[
            ('green', 'Green'),
            ('blue', 'Blue'),
            ('teal', 'Teal'),
            ('navy', 'Navy'),
        ],
        required=False,
        help_text='Chart\'s color scheme. See '
                  'https://github.com/cfpb/cfpb-chart-builder#configuration.')
    data_source = blocks.CharBlock(
        required=True,
        help_text='Location of the chart\'s data source relative to '
                  '"http://files.consumerfinance.gov/data/". For example,'
                  '"consumer-credit-trends/volume_data_Score_Level_AUT.csv".')
    date_published = blocks.DateBlock(
        help_text='Automatically generated when CCT cron job runs'
    )
    description = blocks.CharBlock(
        required=True,
        help_text='Briefly summarize the chart for visually impaired users.')

    has_top_rule_line = blocks.BooleanBlock(
        default=False,
        required=False,
        help_text=('Check this to add a horizontal rule line to top of '
                   'chart block.')
    )

    last_updated_projected_data = blocks.DateBlock(
        help_text='Month of latest entry in dataset'
    )

    metadata = blocks.CharBlock(
        required=False,
        help_text='Optional metadata for the chart to use. '
                  'For example, with CCT this would be the chart\'s "group".')
    note = blocks.CharBlock(
        required=False,
        help_text='Text to display as a footnote. For example, '
                  '"Data from the last six months are not final."')
    y_axis_label = blocks.CharBlock(
        required=False,
        help_text='Custom y-axis label')

    class Meta:
        label = 'Chart Block'
        icon = 'image'
        template = '_includes/organisms/chart.html'

    class Media:
        js = ['chart.js']
Beispiel #7
0
class ThreeColumnsBlock(blocks.StructBlock):
    """
    Shows a callout. Can be used in several positions of a StreamField.
    """

    column_1_text = blocks.RichTextBlock()
    column_1_link_url = URLOrPageBlock(required=False)
    column_1_link_text = blocks.CharBlock(required=False)
    column_1_link_button = blocks.ChoiceBlock(choices=FAIR_BUTTON_CHOICES,
                                              required=False)

    column_2_text = blocks.RichTextBlock()
    column_2_link_url = URLOrPageBlock(required=False)
    column_2_link_text = blocks.CharBlock(required=False)
    column_2_link_button = blocks.ChoiceBlock(choices=FAIR_BUTTON_CHOICES,
                                              required=False)

    column_3_text = blocks.RichTextBlock()
    column_3_link_url = URLOrPageBlock(required=False)
    column_3_link_text = blocks.CharBlock(required=False)
    column_3_link_button = blocks.ChoiceBlock(choices=FAIR_BUTTON_CHOICES,
                                              required=False)

    class Meta:
        icon = 'openquote'
        template = "pages/blocks/three_columns.html"
Beispiel #8
0
class ContentImage(blocks.StructBlock):
    image = atoms.ImageBasic()
    image_width = blocks.ChoiceBlock(
        choices=[('full', 'full'),
                 (470, '470px'),
                 (270, '270px'),
                 (170, '170px')],
        default='full',)
    image_position = blocks.ChoiceBlock(
        choices=[('right', 'right'),
                 ('left', 'left')],
        default='right',
        help_text='Does not apply if the image is full-width',
    )
    text = blocks.RichTextBlock(required=False, label='Caption')
    is_bottom_rule = blocks.BooleanBlock(
        required=False,
        default=True,
        label='Has bottom rule line',
        help_text='Check to add a horizontal rule line to bottom of inset.'
    )

    class Meta:
        icon = 'image'
        template = '_includes/molecules/content-image.html'
        label = 'Image'
Beispiel #9
0
class InfoBlock(core_blocks.StructBlock):

    title = core_blocks.CharBlock(classname="full title", required=False)
    image = image_blocks.ImageChooserBlock(required=False)
    text = core_blocks.RichTextBlock(required=False)
    button = CallToActionBlock(required=False)
    highlight = core_blocks.ChoiceBlock(
        choices=[('', 'None'), ('highlight', 'Highlight (blue)'),
                 ('boxed', 'Boxed'), ('boxed2', 'Boxed Variation'),
                 ('highlight-purple', 'Highlight (purple)')],
        icon='cup',
        required=False,
        help_text='How should this block be displayed?')
    alignment = core_blocks.ChoiceBlock(
        choices=[
            ('vertical', 'vertical'),
            ('horizontal', 'horizontal'),
        ],
        icon='cup',
        default='vertical',
        help_text='How should the text and image be aligned?')

    class Meta:
        template = 'home/blocks/info_block.html'
        icon = 'placeholder'
        label = 'Info Block'
Beispiel #10
0
class BackgroundBlock(blocks.StructBlock):
    type_field = blocks.ChoiceBlock(choices=(
        ('parallaxBg', 'Parallax'),
        ('fixedBg', 'Stilstaand'),
    ))
    background_image = ImageChooserBlock(
        label='Afbeelding',
        help_text='Het achtergrondplaatje van het blok.',
    )
    block_height = blocks.IntegerBlock(
        label='Hoogte',
        help_text='Hoogte van het blok in pixels.',
        min_value=0,
        max_value=999,
        default=250,
    )
    columns = blocks.ChoiceBlock(
        label='Kolommen',
        choices=[('2', 'Twee'), ('1', 'Een')],
        default='2',
    )
    text_left = blocks.RichTextBlock(
        label='Tekst links',
        help_text='Tekst aan de linkerkant op de achtergrond.',
        required=False,
    )
    text_right = blocks.RichTextBlock(
        label='Tekst rechts',
        help_text='Tekst aan de rechterkant op de achtergrond.',
        required=False,
    )
    text_color = ColorPickerBlock(
        label='Kleur tekst',
        required=False,
    )
Beispiel #11
0
class AsciinemaBlock(blocks.StructBlock):
    FONT_SIZE = (
        ('small', _('small')),
        ('medium', _('medium')),
        ('big', _('big')),
    )
    THEME = (
        ('asciinema', ) * 2,
        ('tango', ) * 2,
        ('solarized-dark', ) * 2,
        ('solarized-light', ) * 2,
        ('monokai', ) * 2,
    )

    title = blocks.CharBlock(required=False)
    poster = blocks.CharBlock(
        required=False,
        default='npt:0:0',
        help_text=_('npt:2:34 || data:text/plain,Poster text'))
    document = DocumentChooserBlock(required=True)
    font_size = blocks.ChoiceBlock(FONT_SIZE, default='small')
    theme = blocks.ChoiceBlock(THEME, default='monokai')
    speed = blocks.IntegerBlock(default=1, min_value=1)
    start_at = blocks.CharBlock(default='0',
                                help_text=_('123, mm:ss, hh:mm:ss'))
    cols = blocks.IntegerBlock(default=0, min_value=0, max_value=1024)
    rows = blocks.IntegerBlock(default=5, min_value=0, max_value=1024)
    loop = blocks.BooleanBlock(default=False, required=False)
    preload = blocks.BooleanBlock(default=False, required=False)
    autoplay = blocks.BooleanBlock(default=False, required=False)

    class Meta:
        icon = 'media'
        template = 'wagtail_asciinema/blocks/asciinema_block.html'
Beispiel #12
0
class SnippetList(blocks.StructBlock):
    heading = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(required=False)
    has_top_rule_line = blocks.BooleanBlock(
        default=False,
        required=False,
        help_text=('Check this to add a horizontal rule line to top of '
                   'snippet list.')
    )
    image = atoms.ImageBasic(required=False)
    actions_column_width = blocks.ChoiceBlock(
        label='Width of "Actions" column',
        required=False,
        help_text='Choose the width in % that you wish to set '
                  'the Actions column in a snippet list.',
        choices=[
            ('70', '70%'),
            ('66', '66%'),
            ('60', '60%'),
            ('50', '50%'),
            ('40', '40%'),
            ('33', '33%'),
            ('30', '30%'),
        ],
    )

    snippet_type = blocks.ChoiceBlock(
        choices=get_snippet_type_choices,
        required=True
    )
    show_thumbnails = blocks.BooleanBlock(
        required=False,
        help_text='If selected, each snippet in the list will include a 150px-'
                  'wide image from the snippet\'s thumbnail field.'
    )
    actions = blocks.ListBlock(blocks.StructBlock([
        ('link_label', blocks.CharBlock(
            help_text='E.g., "Download" or "Order free prints"'
        )),
        ('snippet_field', blocks.ChoiceBlock(
            choices=get_snippet_field_choices,
            help_text='Corresponds to the available fields for the selected '
                      'snippet type.'
        )),
    ]))

    tags = blocks.ListBlock(
        blocks.CharBlock(label='Tag'),
        help_text='Enter tag names to filter the snippets. For a snippet to '
                  'match and be output in the list, it must have been tagged '
                  'with all of the tag names listed here. The tag names '
                  'are case-insensitive.'
    )

    class Meta:
        icon = 'table'
        template = '_includes/organisms/snippet-list.html'
Beispiel #13
0
class CodeBlock(blocks.StructBlock):
    """
    Code Highlighting Block
    """
    LANGUAGE_CHOICES = (
        ('python', 'Python'),
        ('bash', 'Bash/Shell'),
        ('html', 'HTML'),
        ('css', 'CSS'),
        ('scss', 'SCSS'),
        ('json', 'JSON'),
    )

    STYLE_CHOICES = (
        ('autumn', 'autumn'),
        ('borland', 'borland'),
        ('bw', 'bw'),
        ('colorful', 'colorful'),
        ('default', 'default'),
        ('emacs', 'emacs'),
        ('friendly', 'friendly'),
        ('fruity', 'fruity'),
        ('github', 'github'),
        ('manni', 'manni'),
        ('monokai', 'monokai'),
        ('murphy', 'murphy'),
        ('native', 'native'),
        ('pastie', 'pastie'),
        ('perldoc', 'perldoc'),
        ('tango', 'tango'),
        ('trac', 'trac'),
        ('vim', 'vim'),
        ('vs', 'vs'),
        ('zenburn', 'zenburn'),
    )

    language = blocks.ChoiceBlock(choices=LANGUAGE_CHOICES)
    style = blocks.ChoiceBlock(choices=STYLE_CHOICES, default='syntax')
    code = blocks.TextBlock()

    class Meta:
        icon = 'code'

    def render(self, value, context):
        src = value['code'].strip('\n')
        lang = value['language']
        lexer = get_lexer_by_name(lang)
        css_classes = ['code', value['style']]

        formatter = get_formatter_by_name(
            'html',
            linenos=None,
            cssclass=' '.join(css_classes),
            noclasses=False,
        )
        return mark_safe(highlight(src, lexer, formatter))
Beispiel #14
0
class ResourceList(blocks.StructBlock):
    heading = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(required=False)
    has_top_rule_line = blocks.BooleanBlock(
        default=False,
        required=False,
        help_text='Check this to add a horizontal rule line above this block.'
    )
    image = atoms.ImageBasic(required=False)
    actions_column_width = blocks.ChoiceBlock(
        label='Width of "Actions" column',
        required=False,
        help_text='Choose the width in % that you wish to set '
                  'the Actions column in a resource list.',
        choices=[
            ('70', '70%'),
            ('66', '66%'),
            ('60', '60%'),
            ('50', '50%'),
            ('40', '40%'),
            ('33', '33%'),
            ('30', '30%'),
        ],
    )
    show_thumbnails = blocks.BooleanBlock(
        required=False,
        help_text='If selected, each resource in the list will include a '
                  '150px-wide image from the resource\'s thumbnail field.'
    )
    actions = blocks.ListBlock(blocks.StructBlock([
        ('link_label', blocks.CharBlock(
            help_text='E.g., "Download" or "Order free prints"'
        )),
        ('snippet_field', blocks.ChoiceBlock(
            choices=[
                ('related_file', 'Related file'),
                ('alternate_file', 'Alternate file'),
                ('link', 'Link'),
                ('alternate_link', 'Alternate link'),
            ],
            help_text='The field that the action link should point to'
        )),
    ]))
    tags = blocks.ListBlock(
        blocks.CharBlock(label='Tag'),
        help_text='Enter tag names to filter the snippets. For a snippet to '
                  'match and be output in the list, it must have been tagged '
                  'with all of the tag names listed here. The tag names '
                  'are case-insensitive.'
    )

    class Meta:
        label = 'Resource List'
        icon = 'table'
        template = '_includes/organisms/resource-list.html'
Beispiel #15
0
class QuoteBlock(blocks.StructBlock):
    quote = blocks.TextBlock(
        label='Citaat',
        required=True,
        max_length=150,
    )

    quote_pos = blocks.ChoiceBlock(
        choices=(
            ('up', 'Boven'),
            ('under', 'Onder'),
        ),
        label='Positie quote',
        help_text='De positie van de quote (boven of onder het plaatje).',
    )

    quote_size = blocks.ChoiceBlock(
        choices=(
            ('24px', '24px'),
            ('40px', '40px'),
        ),
        label='Quote tekstgrootte',
        help_text='De tekstgroote van de quote.',
    )

    quote_background_color = ColorPickerBlock(
        label='Achtergrondkleur',
        required=False,
        help_text='De achtergrondkleur van de quote.')
    quote_color = ColorPickerBlock(label='Kleur tekst',
                                   required=False,
                                   help_text='De tekstkleur van de quote.')

    logo = ImageChooserBlock(required=False)

    name = blocks.CharBlock(
        label='Naam',
        max_length=50,
        help_text='Naam van de persoon achter het citaat.',
    )

    company = blocks.CharBlock(
        label='Bedrijf',
        max_length=50,
        help_text='Naam van het bedrijf achter het citaat.',
    )

    city = blocks.CharBlock(label='Plaats', max_length=50, help_text='Plaats')

    link = blocks.PageChooserBlock(
        label='Interne link',
        can_choose_root=True,
        required=False,
    )
Beispiel #16
0
class TableStructBlock(blocks.StructBlock):
    type_table = blocks.ChoiceBlock(
        choices = [(' ', 'Gewone tabel'), ('price-table', 'Prijs tabel')],
        label='Type tabel',
    )
    table_borders = blocks.ChoiceBlock(
        choices = [
            ('no-borders', 'Geen lijnen'), ('column-borders', 'Kolom lijnen'),
            ('row-borders', 'Regel lijnen'), ('all-borders', 'Kolom en regel lijnen'),
        ],
        label='Tabel lijnen'
    )
    table_header_rows = blocks.IntegerBlock(
        label = 'Tabelheaderrijen',
        min_value = 0,
        max_value = 100,
        default = 2,
    )
    table_footer_rows = blocks.IntegerBlock(
        label = 'Tabelfooterrijen',
        min_value = 0,
        max_value = 100,
        default = 2,
    )
    table_header_background = ColorPickerBlock(
        label = 'Tabelheader achtergrondkleur',
        required = False,
    )
    table_header_color = ColorPickerBlock(
        label = 'Tabelheader tekstkleur',
        required = False,
    )
    table_header_text_size = blocks.IntegerBlock(
        label = 'Tabelheader grootte tekst',
        help_text = 'Tabelheader grootte van de tekst.',
        min_value = 1,
        max_value = 100,
        default = 20,
    )
    table_footer_background = ColorPickerBlock(
        label = 'Tabelfooter achtergrondkleur',
        required = False,
    )
    table_footer_color = ColorPickerBlock(
        label = 'Tabelfooter tekstkleur',
        required = False,
    )
    table = TableBlock(
        table_options=TABLE_OPTIONS,
        label='Tabel',
        help_text='HTML is mogelijk in de tabel'
    )
Beispiel #17
0
class TableStructBlock(blocks.StructBlock):
    type_table = blocks.ChoiceBlock(
        choices = [(' ', 'Ordinary table'), ('price-table', 'Price table')],
        label=_('Type table'),
    )
    table_borders = blocks.ChoiceBlock(
        choices = [
            ('no-borders', 'No lines'), ('column-borders', 'Column lines'),
            ('row-borders', 'Now lines'), ('all-borders', 'Column and line lines'),
        ],
        label=_('Table lines')
    )
    table_header_rows = blocks.IntegerBlock(
        label = _('Table header'),
        min_value = 0,
        max_value = 100,
        default = 2,
    )
    table_footer_rows = blocks.IntegerBlock(
        label = _('Table footer'),
        min_value = 0,
        max_value = 100,
        default = 2,
    )
    table_header_background = ColorPickerBlock(
        label = _('Table header background'),
        required = False,
    )
    table_header_color = ColorPickerBlock(
        label = _('Table header color'),
        required = False,
    )
    table_header_text_size = blocks.IntegerBlock(
        label = _('Table header size text'),
        help_text = 'Table header size of the text.',
        min_value = 1,
        max_value = 100,
        default = 20,
    )
    table_footer_background = ColorPickerBlock(
        label = _('Table footer background color'),
        required = False,
    )
    table_footer_color = ColorPickerBlock(
        label = _('Table footer color'),
        required = False,
    )
    table = TableBlock(
        label=_('Tabel'),
        table_options=TABLE_OPTIONS,
        help_text='HTML is possible in the table'
    )
Beispiel #18
0
class TwoColumnBlock(blocks.StructBlock):
    COLOUR_CHOICES = (
        ('theme-white', 'White'),
        ('theme-black', 'Black'),
        ('theme-darker', 'Dark Gray'),
        ('theme-body-color', 'Body Color'),
        ('theme-primary', 'Primary Color'),
        ('theme-secondary', 'Secondary Color'),
    )

    background = blocks.ChoiceBlock(choices=COLOUR_CHOICES, default="white")

    left_column = blocks.StreamBlock([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('google_map', GoogleMapBlock()),
    ], icon='arrow-left', label='Left column content')

    right_column = blocks.StreamBlock([
        ('heading', blocks.CharBlock(classname="full title")),
        ('paragraph', blocks.RichTextBlock()),
        ('image', ImageChooserBlock()),
        ('google_map', GoogleMapBlock()),
    ], icon='arrow-right', label='Right column content')

    class Meta:
        template = 'homepage/two_column_block.html'
        icon = 'placeholder'
        label = 'Two Columns'
class PersonalisedStructBlock(blocks.StructBlock):
    """Struct block that allows personalisation per block."""

    segment = blocks.ChoiceBlock(
        choices=list_segment_choices,
        required=False, label=_("Personalisation segment"),
        help_text=_("Only show this content block for users in this segment"))

    def render(self, value, context=None):
        """Only render this content block for users in this segment.

        :param value: The value from the block
        :type value: dict
        :param context: The context containing the request
        :type context: dict
        :returns: The provided block if matched, otherwise an empty string
        :rtype: blocks.StructBlock or empty str

        """
        # TODO: move logic to its own class instead of getting it from the
        # session.
        user_segments = context['request'].session['segments']

        if value['segment']:
            for segment in user_segments:
                if segment['id'] == int(value['segment']):
                    return super(PersonalisedStructBlock, self).render(
                        value, context)

        return ""
Beispiel #20
0
    def test_named_groups_with_blank_option(self):
        block = blocks.ChoiceBlock(
            choices=[
                ('Alcoholic', [
                    ('gin', 'Gin'),
                    ('whisky', 'Whisky'),
                ]),
                ('Non-alcoholic', [
                    ('tea', 'Tea'),
                    ('coffee', 'Coffee'),
                ]),
                ('Not thirsty', [
                    ('', 'No thanks')
                ]),
            ],
            required=False)

        # test rendering with the blank option selected
        html = block.render_form(None, prefix='beverage')
        self.assertIn('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertNotIn('<option value="" selected="selected">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<optgroup label="Alcoholic">', html)
        self.assertIn('<option value="tea">Tea</option>', html)
        self.assertIn('<option value="" selected="selected">No thanks</option>', html)

        # test rendering with a non-blank option selected
        html = block.render_form('tea', prefix='beverage')
        self.assertIn('<select id="beverage" name="beverage" placeholder="">', html)
        self.assertNotIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
        self.assertNotIn('<option value="" selected="selected">%s</option>' % self.blank_choice_dash_label, html)
        self.assertIn('<optgroup label="Alcoholic">', html)
        self.assertIn('<option value="tea" selected="selected">Tea</option>', html)
Beispiel #21
0
 def test_render_non_required_choice_block(self):
     block = blocks.ChoiceBlock(choices=[('tea', 'Tea'), ('coffee', 'Coffee')], required=False)
     html = block.render_form('coffee', prefix='beverage')
     self.assertIn('<select id="beverage" name="beverage" placeholder="">', html)
     self.assertIn('<option value="">%s</option>' % self.blank_choice_dash_label, html)
     self.assertIn('<option value="tea">Tea</option>', html)
     self.assertIn('<option value="coffee" selected="selected">Coffee</option>', html)
Beispiel #22
0
class HeroDonateBlock(blocks.StructBlock):
    hero_image = ImageChooserBlock(required=False)
    background_color = blocks.TextBlock(required=False)
    padding = blocks.TextBlock(required=False)
    amount_one = blocks.TextBlock(required=False)
    amount_two = blocks.TextBlock(required=False)
    amount_three = blocks.TextBlock(required=False)
    amount_four = blocks.TextBlock(required=False)
    amount_five = blocks.TextBlock(required=False)
    amount_six = blocks.TextBlock(required=False)
    logo = blocks.ChoiceBlock(choices=[
        ('hide', 'Hide'),
        ('show', 'Show'),
        ('animate', 'Animate'),
    ])
    hero_content = blocks.StreamBlock([
        ('HTML', HtmlBlock()),
        ('WYSIWYG', WysiwygBlock()),
        ('Row', RowBlock()),
    ])
    thankyou_content = blocks.StreamBlock([
        ('HTML', HtmlBlock()),
        ('WYSIWYG', WysiwygBlock()),
        ('Row', RowBlock()),
    ])

    class Meta:
        template = 'blocks/hero_donate_block.html'
        icon = 'pick'
Beispiel #23
0
class NotificationBlock(blocks.StructBlock):
    message = blocks.CharBlock(required=True,
                               help_text='Main message of the notification')
    explanation = blocks.TextBlock(
        required=False, help_text='An explanation for the notification')
    notification_type = blocks.ChoiceBlock(required=True,
                                           choices=[
                                               ('success', 'Success'),
                                               ('warning', 'Warning'),
                                               ('error', 'Error'),
                                           ],
                                           default='warning')

    def get_context(self, value, parent_context=None):
        context = super(NotificationBlock,
                        self).get_context(value, parent_context=parent_context)

        if value.get('notification_type') == 'success':
            context['notification_icon'] = 'approved-round'
        else:
            context['notification_icon'] = (value.get('notification_type') +
                                            '-round')

        return context

    class Meta:
        icon = 'warning'
        template = 'regulations3k/notification.html'
Beispiel #24
0
class StreamBlock(blocks.StreamBlock):
    paragraph = blocks.RichTextBlock(icon="pilcrow",
                                     template="blocks/paragraph.html")
    header = blocks.CharBlock(classname="title",
                              icon="fa-header",
                              template="blocks/h3.html")
    image = blocks.StructBlock(
        [('image', ImageChooserBlock()),
         ('caption', blocks.CharBlock(blank=True, required=False)),
         ('style',
          blocks.ChoiceBlock(choices=[('', 'Select an image size'),
                                      ('full', 'Full-width'),
                                      ('half', 'Half-width')],
                             required=False))],
        icon="image",
        template="blocks/image.html")
    blockquote = blocks.StructBlock([
        ('text', blocks.TextBlock()),
        ('attribute_name',
         blocks.CharBlock(
             blank=True, required=False, label='e.g. Guy Picciotto')),
        ('attribute_group',
         blocks.CharBlock(blank=True, required=False, label='e.g. Fugazi')),
    ],
                                    icon="openquote",
                                    template="blocks/blockquote.html")
class PersonalisedStructBlock(blocks.StructBlock):
    """Struct block that allows personalisation per block."""

    segment = blocks.ChoiceBlock(
        choices=list_segment_choices,
        required=False,
        label=_("Personalisation segment"),
        help_text=_("Only show this content block for users in this segment"))

    def render(self, value, context=None):
        """Only render this content block for users in this segment.

        :param value: The value from the block
        :type value: dict
        :param context: The context containing the request
        :type context: dict
        :returns: The provided block if matched, otherwise an empty string
        :rtype: blocks.StructBlock or empty str

        """
        request = context['request']
        adapter = get_segment_adapter(request)
        user_segments = adapter.get_segments()

        if value['segment']:
            for segment in user_segments:
                if segment.id == int(value['segment']):
                    return super(PersonalisedStructBlock,
                                 self).render(value, context)

        return ""
Beispiel #26
0
class RelatedPosts(blocks.StructBlock):
    limit = blocks.CharBlock(default='3', label='Limit')
    show_heading = blocks.BooleanBlock(
        required=False,
        default=True,
        label='Show Heading and Icon?',
        help_text='This toggles the heading and' +
        ' icon for the related types.')
    header_title = blocks.CharBlock(default='Further reading',
                                    label='Slug Title')

    relate_posts = blocks.BooleanBlock(required=False,
                                       default=True,
                                       label='Blog Posts',
                                       editable=False)
    relate_newsroom = blocks.BooleanBlock(required=False,
                                          default=True,
                                          label='Newsroom',
                                          editable=False)
    relate_events = blocks.BooleanBlock(required=False,
                                        default=True,
                                        label='Events')

    specific_categories = blocks.ListBlock(blocks.ChoiceBlock(
        choices=ref.related_posts_categories, required=False),
                                           required=False)

    class Meta:
        icon = 'link'
        template = '_includes/molecules/related-posts.html'
Beispiel #27
0
class TripleFrameBlock(StructBlock):

    columns = blocks.ChoiceBlock(label=_('Proportions'),
                                 choices=[
                                     ('4-4-4', _('1/3 + 1/3 + 1/3')),
                                     ('6-3-3', _('1/2 + 1/4 + 1/4')),
                                     ('3-6-3', _('1/4 + 1/2 + 1/4')),
                                     ('3-3-6', _('1/4 + 1/4 + 1/2')),
                                 ],
                                 required=True,
                                 default='4-4-4',
                                 icon='fa fa-columns')

    left = blocks.StreamBlock(STREAMFIELD_BLOCKS_NOFRAMES, icon='cogs')
    middle = blocks.StreamBlock(STREAMFIELD_BLOCKS_NOFRAMES, icon='cogs')
    right = blocks.StreamBlock(STREAMFIELD_BLOCKS_NOFRAMES, icon='cogs')

    class Meta(object):
        icon = 'fa fa-columns'
        template = 'cosinnus/wagtail/widgets/triple_frame.html'

    def get_context(self, value):
        context = super(TripleFrameBlock, self).get_context(value)
        context['left'] = value.get('left')
        context['middle'] = value.get('middle')
        context['right'] = value.get('right')
        context['columns'] = value.get('columns')
        return context
Beispiel #28
0
class FormFieldWithButton(blocks.StructBlock):
    btn_text = blocks.CharBlock(required=False)

    required = blocks.BooleanBlock(required=False)

    info = blocks.RichTextBlock(required=False, label="Disclaimer")
    inline_info = blocks.BooleanBlock(
        required=False,
        label='Inline disclaimer',
        help_text=('Show disclaimer on same line as button. Only select '
                   'this option if the disclaimer text is a few words (ie, '
                   '"Privacy Act statement") rather than a full sentence.'))
    label = blocks.CharBlock(required=True)
    type = blocks.ChoiceBlock(choices=[
        ('text', 'Text'),
        ('checkbox', 'Checkbox'),
        ('email', 'Email'),
        ('number', 'Number'),
        ('url', 'URL'),
        ('radio', 'Radio'),
    ],
                              required=False)
    placeholder = blocks.CharBlock(required=False)

    class Meta:
        icon = 'mail'
        template = '_includes/molecules/form-field-with-button.html'
Beispiel #29
0
class CodeBlock(blocks.StructBlock):
    """
    Code Highlighting Block
    """
    LANGUAGE_CHOICES = (
        ('python', 'Python'),
        ('javascript', 'Javascript'),
        ('json', 'JSON'),
        ('bash', 'Bash/Shell'),
        ('html', 'HTML'),
        ('css', 'CSS'),
        ('scss', 'SCSS'),
        ('yaml', 'YAML'),
    )

    language = blocks.ChoiceBlock(choices=LANGUAGE_CHOICES)
    code = blocks.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))
Beispiel #30
0
class FeaturedContent(blocks.StructBlock):
    heading = blocks.CharBlock(required=False)
    body = blocks.RichTextBlock(required=False)

    category = blocks.ChoiceBlock(choices=ref.fcm_types, required=False)
    post = blocks.PageChooserBlock(required=False)

    show_post_link = blocks.BooleanBlock(required=False,
                                         label="Render post link?")
    post_link_text = blocks.CharBlock(required=False)

    image = atoms.ImageBasic(required=False)
    links = blocks.ListBlock(atoms.Hyperlink(required=False),
                             label='Additional Links')

    video = blocks.StructBlock([
        ('id',
         blocks.CharBlock(
             required=False,
             help_text=
             'e.g In \"https://www.youtube.com/watch?v=en0Iq8II4fA\", the ID is everything after the \"?v=\"'
         )),
        ('url', blocks.CharBlock(default='/', required=False)),
        ('height', blocks.CharBlock(default='320', required=False)),
        ('width', blocks.CharBlock(default='568', required=False)),
    ])

    class Meta:
        template = '_includes/molecules/featured-content.html'
        icon = 'doc-full-inverse'
        label = 'Featured Content'
        classname = 'block__flush'