Example #1
0
class PieChartBlock(BasePieChartBlock):
    """
    Basic pie chart block
    """
    hole = blocks.FloatBlock(
        default=0,
        max_value=0.9,
        min_value=0,
        help_text='Hole size for pie chart',
    )

    marker_line_color = NativeColorBlock(
        required=False,
        help_text='Line color for pie chart',
    )

    marker_line_width = blocks.IntegerBlock(
        default=1,
        min_value=0,
        max_value=10,
        help_text='Line width for pie chart',
    )

    layout = LayoutChooserBlock(required=False)

    def get_trace_fields(self):
        return ['hole', 'marker_line_color', 'marker_line_width']
class BasicSection(blocks.StructBlock):
    """Basic section with a solid color background"""
    background_color = NativeColorBlock(
        required=True, help_text="The hex value of the background")
    text_color = NativeColorBlock(required=True,
                                  help_text="The hex value of the text")
    full_width = blocks.BooleanBlock(required=False)
    bottom_effect = blocks.ChoiceBlock(required=False,
                                       choices=[('zigzag', 'zigzag'),
                                                ('arrow', 'arrow'),
                                                ('arrow_big', 'arrow_big')])
    content = blocks.StreamBlock(all_blocks)

    class Meta:
        template = 'wagtail_block_collection/sections/basic_section.html'
        label = "Basic color background"
    def test_form_uses_proper_input_type(self):
        block = NativeColorBlock()
        html = block.field.widget.render_html(name="cat",
                                              value="#333333",
                                              attrs={})

        self.assertEqual(block.field.widget.__class__, ColorInputWidget)
        self.assertIn('type="color"', html)
Example #4
0
class SidebarHeaderBlock(blocks.StructBlock):
    title = blocks.CharBlock()
    color = NativeColorBlock('color', default="#333d44")
    image = ImageChooserBlock()
    content = blocks.RichTextBlock(required=False)

    class Meta:
        template = 'blocks/sidebar/header.html'
class SectionImgBesideContent(blocks.StructBlock):
    """Show a full width and height image with steamfields beside that"""
    background_img = ImageChooserBlock(required=True)
    background_color = NativeColorBlock(required=True)
    text_color = NativeColorBlock(
        required=True,
        help_text="All the text inside the section will get this collor")
    position = blocks.ChoiceBlock(choices=[('left', 'left'), ('right',
                                                              'right')])
    bottom_effect = blocks.ChoiceBlock(required=False,
                                       choices=[('zigzag', 'zigzag'),
                                                ('arrow', 'arrow'),
                                                ('arrow_big', 'arrow_big')])
    content = blocks.StreamBlock(all_blocks)

    class Meta:
        template = 'wagtail_block_collection/sections/section_img_beside_content.html'
        label = "Section img with content beside"
class SectionGradient(blocks.StructBlock):
    """Section with a CSS gradient"""
    text_color = NativeColorBlock(required=True)
    angel = blocks.IntegerBlock(min_value=0, max_value=360, required=True)
    full_width = blocks.BooleanBlock(required=False)
    bottom_effect = blocks.ChoiceBlock(required=False,
                                       choices=[('zigzag', 'zigzag'),
                                                ('arrow', 'arrow'),
                                                ('arrow_big', 'arrow_big')])
    stops = blocks.ListBlock(
        blocks.StructBlock([('color', NativeColorBlock(required=True)),
                            ('stop',
                             blocks.IntegerBlock(min_value=0,
                                                 max_value=100))]))
    content = blocks.StreamBlock(all_blocks)

    class Meta:
        template = 'wagtail_block_collection/sections/section_gradient.html'
        label = "Section with color gradient background"
class CollapseBlockButton(blocks.StructBlock):
    """Collapse some context using a button"""
    button_text = blocks.CharBlock(required=True)
    button_background_color = NativeColorBlock(required=True)
    button_text_color = NativeColorBlock(required=True)
    button_size = blocks.ChoiceBlock(
        choices=[('btn-lg', 'big'), (' ', 'normal'), ('btn-ls', 'small')])
    button_google_font = blocks.CharBlock(
        required=False, help_text="Choose a font from Google Font")
    content_background_show = blocks.BooleanBlock(
        help_text="If selected the content wil be on a card")
    content_background_color = NativeColorBlock(required=False)
    content = blocks.StreamBlock(content_blocks)

    class Meta:
        icon = "fa-compress"
        template = 'wagtail_block_collection/layout/collapse_button.html'
        group = "Layout"
        label = "Collapse with button"
class SectionBaseBlock(StructBlock):
    """ Section Base Block - Ued by each section """
    # Layout
    section_color_theme = ChoiceBlock(
        required=False,
        choices=cr_settings['SECTION_COLOR_THEME_CHOICES'],
        default=cr_settings['SECTION_COLOR_THEME_CHOICES_DEFAULT'],
        label='Theme',
    )
    section_top_bottom_padding = ChoiceBlock(
        required=False,
        choices=cr_settings['SECTION_TOP_BOTTOM_PADDING_CHOICES'],
        default=cr_settings['SECTION_TOP_BOTTOM_PADDING_CHOICES_DEFAULT'],
        label='Height',
    )
    section_container_width = ChoiceBlock(
        required=False,
        choices=cr_settings['SECTION_CONTAINER_WIDTH_CHOICES'],
        default=cr_settings['SECTION_CONTAINER_WIDTH_CHOICES_DEFAULT'],
        label='Width',
    )
    # Background
    section_background_type = ChoiceBlock(
        required=False,
        choices=cr_settings['SECTION_BACKGROUND_TYPE_CHOICES'],
        default=cr_settings['SECTION_BACKGROUND_TYPE_CHOICES_DEFAULT'],
        label='Background Type',
    )
    section_background_color = NativeColorBlock(
        required=False,
        default='#F37E77',
        label='Color 1',
    )
    section_background_color_2 = NativeColorBlock(
        required=False,
        default='#F37E77',
        label='Color 2',
    )
    section_background_image = ImageChooserBlock(
        required=False,
        label='Image',
    )
class BasicButtonBlock(blocks.StructBlock):
    """A button with some bootstrap styling options"""
    page = blocks.PageChooserBlock(
        required=False, help_text="the page you want tot point the button to")
    url = blocks.URLBlock(required=False, help_text="Point to a external URL")
    text = blocks.CharBlock(required=True, help_text="The text on the button")
    background_color = NativeColorBlock(required=True,
                                        help_text="HEX value of a color")
    text_color = NativeColorBlock(required=True,
                                  help_text="HEX value of a color")
    size = blocks.ChoiceBlock(choices=[('btn-lg',
                                        'big'), (' ',
                                                 'normal'), ('btn-sm',
                                                             'small')])
    google_font = blocks.CharBlock(required=False,
                                   help_text="Choose a font from Google Font")

    class Meta:
        icon = 'fa-square'
        template = 'wagtail_block_collection/basic/button_block.html'
        group = "Basic"
        label = "Button"
class IconBlock(blocks.StructBlock):
    """Basic fontawesome icons"""
    icon_color = NativeColorBlock(required=True)
    icon_size = blocks.CharBlock(
        max_length=10,
        required=True,
        help_text="any CSS unit supported px, %, rem, vh enz")
    icon_icon = IconBlock(required=True)

    class Meta:
        icon = 'pick'
        template = 'wagtail_block_collection/basic/icon_block.html'
        group = "Basic"
        label = "icon"
class SectionImg(blocks.StructBlock):
    """Section with a image background"""
    background_img = ImageChooserBlock(required=True)
    text_color = NativeColorBlock(required=True,
                                  help_text="The hex value of the text")
    full_width = blocks.BooleanBlock(required=False)
    bottom_effect = blocks.ChoiceBlock(required=False,
                                       choices=[('zigzag', 'zigzag'),
                                                ('arrow', 'arrow'),
                                                ('arrow_big', 'arrow_big')])
    content = blocks.StreamBlock(all_blocks)

    class Meta:
        template = 'wagtail_block_collection/sections/section_img.html'
        label = "Section img background"
class Line(blocks.StructBlock):
    """A simple line with a few options"""
    width = blocks.CharBlock(
        required=False, help_text="any CSS unit supported px, %, rem, vh enz")
    thickness = blocks.CharBlock(
        required=True, help_text="any CSS unit supported px, %, rem, vh enz")
    color = NativeColorBlock(required=False)
    style = blocks.ChoiceBlock(required=True,
                               choices=[('solid', 'solid'),
                                        ('dashed', 'dashed'),
                                        ('dotted', 'dotted')])

    class Meta:
        icon = 'fa-ellipsis-h'
        template = 'wagtail_block_collection/basic/line_block.html'
        group = "Basic"
        label = "Line"
Example #13
0
class BarChartBlock(BaseBarChartBlock):
    """
    Basic bar chart block
    """
    orientation = blocks.ChoiceBlock(
        default='v',
        choices=ORIENTATION_CHOICES,
        help_text='Display as a vertical or horizontal bar chart',
    )

    marker_line_color = NativeColorBlock(
        required=False,
        help_text='Line color for bar chart',
    )

    marker_line_width = blocks.IntegerBlock(
        default=1,
        min_value=0,
        max_value=10,
        help_text='Line width for bar chart',
    )

    barmode = blocks.ChoiceBlock(
        default='group',
        choices=BARMODE_CHOICES,
        help_text='Display as a grouped or stacked bar chart',
    )

    bargroupgap = blocks.FloatBlock(
        default=0.1,
        min_value=0,
        max_value=0.5,
        help_text='Gap between bars of the same location coordinate',
    )

    layout = LayoutChooserBlock(required=False)

    def get_trace_fields(self):
        return ['orientation', 'marker_line_color', 'marker_line_width']

    def get_layout_fields(self):
        return ['barmode', 'bargroupgap']
class BasicCardDeck(blocks.StructBlock):
    """Bootstrap card deck"""
    title = blocks.CharBlock(required=False, max_length=128)
    cards = blocks.ListBlock(
        blocks.StructBlock([
            ("image", ImageChooserBlock(required=False)),
            ("title", blocks.CharBlock(required=False, max_length=64)),
            ("description", blocks.TextBlock(required=False)),
            ("button_page", blocks.PageChooserBlock(required=False)),
            ("button_url",
             blocks.URLBlock(required=False,
                             help_text="is used if no page is set")),
            ("background_color", NativeColorBlock(required=False)),
        ]))

    class Meta:
        icon = 'fa-th'
        template = "wagtail_block_collection/card_deck_block.html"
        group = "Cards"
        label = "Card Equal Height"
class TextBlock(blocks.StructBlock):
    """The main text block using the rich text option"""
    text_align = blocks.ChoiceBlock(
        required=False,
        help_text="If not set section settings wil be used",
        choices=[
            ('left', 'left'),
            ('center', 'center'),
            ('right', 'right'),
        ])
    text_color = NativeColorBlock(
        required=False, help_text="If not set section settings wil be used")
    google_font = blocks.CharBlock(required=False,
                                   help_text="Choose a font from Google Font")
    text = blocks.RichTextBlock(required=True, help_text="Text for this block")

    class Meta:
        icon = 'fa-font'
        template = 'wagtail_block_collection/basic/text_block.html'
        group = "Basic"
        label = "Text"
 def test_color_block_supports_default_value(self):
     default_value = NativeColorBlock(default="#333333").get_default()
     self.assertEqual("#333333", default_value)
    def test_that_hex_colors_are_validated(self):
        block = NativeColorBlock()
        with self.assertRaises(ValidationError) as ctx:
            block.clean("Invalid")

        self.assertTrue("Enter a valid color hash" in str(ctx.exception))
Example #18
0
class PageWithStreamfield(Page):
    body = StreamField([
        ("color", NativeColorBlock()),
    ])
Example #19
0
    def test_form_uses_proper_input_type(self):
        block = NativeColorBlock()
        html = block.render_form("#333333")

        self.assertIn('type="color"', html)
    def test_color_block_render(self):
        block = NativeColorBlock()
        html = block.render("#333333")

        self.assertEqual("#333333", html)
Example #21
0
class BannerBlock(StructBlock):
    text = blocks.TextBlock(required=True)
    url = blocks.URLBlock(required=True)
    text_color = NativeColorBlock(default="#000000")
    banner_color = NativeColorBlock(default="#000000")