diff --git a/CHANGELOG.txt b/CHANGELOG.txt index fea83d56d..1e1527fd0 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,7 @@ Changelog * Optimised Site.find_for_request to only perform one database query (Matthew Downey) * Notification messages on creating / editing sites now include the site name if specified (Chris Rogers) * Added ``--schema-only`` option to ``update_index`` management command + * Added meaningful default icons to `StreamField` blocks (Benjamin Bach) * Fix: The currently selected day is now highlighted only in the correct month in date pickers (Jonas Lergell) * Fix: Fixed crash when an image without a source file was resized with the "dynamic serve view" * Fix: Registered settings admin menu items now show active correctly (Matthew Downey) diff --git a/docs/releases/1.5.rst b/docs/releases/1.5.rst index ccb3a07de..ac582b920 100644 --- a/docs/releases/1.5.rst +++ b/docs/releases/1.5.rst @@ -39,6 +39,7 @@ Minor features * Optimised Site.find_for_request to only perform one database query (Matthew Downey) * Notification messages on creating / editing sites now include the site name if specified (Chris Rogers) * Added ``--schema-only`` option to ``update_index`` management command + * Added meaningful default icons to ``StreamField`` blocks (Benjamin Bach) Bug fixes ~~~~~~~~~ diff --git a/wagtail/tests/testapp/blocks.py b/wagtail/tests/testapp/blocks.py index c4f5add34..a00825c43 100644 --- a/wagtail/tests/testapp/blocks.py +++ b/wagtail/tests/testapp/blocks.py @@ -13,6 +13,7 @@ class LinkBlock(blocks.StructBlock): return context class Meta: + icon = "site" template = 'tests/blocks/link_block.html' @@ -21,4 +22,5 @@ class SectionBlock(blocks.StructBlock): body = blocks.RichTextBlock() class Meta: + icon = "form" template = 'tests/blocks/section_block.html' diff --git a/wagtail/wagtailcore/blocks/field_block.py b/wagtail/wagtailcore/blocks/field_block.py index ac50d60d0..4c34ffa0b 100644 --- a/wagtail/wagtailcore/blocks/field_block.py +++ b/wagtail/wagtailcore/blocks/field_block.py @@ -19,8 +19,6 @@ from .base import Block class FieldBlock(Block): """A block that wraps a Django form field""" - class Meta: - default = None def id_for_label(self, prefix): return self.field.widget.id_for_label(prefix) @@ -76,8 +74,16 @@ class FieldBlock(Block): # the one this block works with natively return self.value_from_form(self.field.clean(self.value_for_form(value))) + class Meta: + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + default = None + class CharBlock(FieldBlock): + def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs): # CharField's 'label' and 'initial' parameters are not exposed, as Block handles that functionality natively # (via 'label' and 'default') @@ -94,6 +100,7 @@ class CharBlock(FieldBlock): class TextBlock(FieldBlock): + def __init__(self, required=True, help_text=None, rows=1, max_length=None, min_length=None, **kwargs): self.field_options = { 'required': required, @@ -114,8 +121,12 @@ class TextBlock(FieldBlock): def get_searchable_content(self, value): return [force_text(value)] + class Meta: + icon = "pilcrow" + class URLBlock(FieldBlock): + def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs): self.field = forms.URLField( required=required, @@ -125,8 +136,12 @@ class URLBlock(FieldBlock): ) super(URLBlock, self).__init__(**kwargs) + class Meta: + icon = "site" + class BooleanBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): # NOTE: As with forms.BooleanField, the default of required=True means that the checkbox # must be ticked to pass validation (i.e. it's equivalent to an "I agree to the terms and @@ -135,8 +150,12 @@ class BooleanBlock(FieldBlock): self.field = forms.BooleanField(required=required, help_text=help_text) super(BooleanBlock, self).__init__(**kwargs) + class Meta: + icon = "tick-inverse" + class DateBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): self.field_options = {'required': required, 'help_text': help_text} super(DateBlock, self).__init__(**kwargs) @@ -157,8 +176,12 @@ class DateBlock(FieldBlock): else: return parse_date(value) + class Meta: + icon = "date" + class TimeBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): self.field_options = {'required': required, 'help_text': help_text} super(TimeBlock, self).__init__(**kwargs) @@ -176,8 +199,12 @@ class TimeBlock(FieldBlock): else: return parse_time(value) + class Meta: + icon = "time" + class DateTimeBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): self.field_options = {'required': required, 'help_text': help_text} super(DateTimeBlock, self).__init__(**kwargs) @@ -195,8 +222,12 @@ class DateTimeBlock(FieldBlock): else: return parse_datetime(value) + class Meta: + icon = "date" + class ChoiceBlock(FieldBlock): + choices = () def __init__(self, choices=None, required=True, help_text=None, **kwargs): @@ -259,6 +290,12 @@ class ChoiceBlock(FieldBlock): return [v] return [] # Value was not found in the list of choices + class Meta: + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + class RichTextBlock(FieldBlock): @@ -299,8 +336,12 @@ class RichTextBlock(FieldBlock): def get_searchable_content(self, value): return [force_text(value.source)] + class Meta: + icon = "doc-full" + class RawHTMLBlock(FieldBlock): + def __init__(self, required=True, help_text=None, max_length=None, min_length=None, **kwargs): self.field = forms.CharField( required=required, help_text=help_text, max_length=max_length, min_length=min_length, @@ -330,6 +371,7 @@ class RawHTMLBlock(FieldBlock): class ChooserBlock(FieldBlock): + def __init__(self, required=True, help_text=None, **kwargs): self.required = required self.help_text = help_text @@ -381,8 +423,15 @@ class ChooserBlock(FieldBlock): value = value.pk return super(ChooserBlock, self).clean(value) + class Meta: + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + class PageChooserBlock(ChooserBlock): + def __init__(self, can_choose_root=False, **kwargs): self.can_choose_root = can_choose_root super(PageChooserBlock, self).__init__(**kwargs) @@ -403,6 +452,9 @@ class PageChooserBlock(ChooserBlock): else: return '' + class Meta: + icon = "redirect" + # Ensure that the blocks defined here get deconstructed as wagtailcore.blocks.FooBlock # rather than wagtailcore.blocks.field.FooBlock diff --git a/wagtail/wagtailcore/blocks/list_block.py b/wagtail/wagtailcore/blocks/list_block.py index 9f0da0f88..9bf17a636 100644 --- a/wagtail/wagtailcore/blocks/list_block.py +++ b/wagtail/wagtailcore/blocks/list_block.py @@ -17,6 +17,7 @@ __all__ = ['ListBlock'] class ListBlock(Block): + def __init__(self, child_block, **kwargs): super(ListBlock, self).__init__(**kwargs) @@ -159,6 +160,13 @@ class ListBlock(Block): errors.extend(self.child_block.check(**kwargs)) return errors + class Meta: + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + + DECONSTRUCT_ALIASES = { ListBlock: 'wagtail.wagtailcore.blocks.ListBlock', } diff --git a/wagtail/wagtailcore/blocks/stream_block.py b/wagtail/wagtailcore/blocks/stream_block.py index 0af7b1ace..267de6ea1 100644 --- a/wagtail/wagtailcore/blocks/stream_block.py +++ b/wagtail/wagtailcore/blocks/stream_block.py @@ -33,8 +33,6 @@ class StreamBlockValidationError(ValidationError): class BaseStreamBlock(Block): - class Meta: - default = [] def __init__(self, local_blocks=None, **kwargs): self._constructor_kwargs = kwargs @@ -243,6 +241,13 @@ class BaseStreamBlock(Block): return errors + class Meta: + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + default = [] + class StreamBlock(six.with_metaclass(DeclarativeSubBlocksMetaclass, BaseStreamBlock)): pass diff --git a/wagtail/wagtailcore/blocks/struct_block.py b/wagtail/wagtailcore/blocks/struct_block.py index 59a824d0a..6b0c98f77 100644 --- a/wagtail/wagtailcore/blocks/struct_block.py +++ b/wagtail/wagtailcore/blocks/struct_block.py @@ -19,11 +19,6 @@ __all__ = ['BaseStructBlock', 'StructBlock', 'StructValue'] class BaseStructBlock(Block): - class Meta: - default = {} - template = "wagtailadmin/blocks/struct.html" - form_classname = 'struct-block' - form_template = 'wagtailadmin/block_forms/struct.html' def __init__(self, local_blocks=None, **kwargs): self._constructor_kwargs = kwargs @@ -160,6 +155,16 @@ class BaseStructBlock(Block): return errors + class Meta: + default = {} + template = "wagtailadmin/blocks/struct.html" + form_classname = 'struct-block' + form_template = 'wagtailadmin/block_forms/struct.html' + # No icon specified here, because that depends on the purpose that the + # block is being used for. Feel encouraged to specify an icon in your + # descendant block type + icon = "placeholder" + class StructBlock(six.with_metaclass(DeclarativeSubBlocksMetaclass, BaseStructBlock)): pass diff --git a/wagtail/wagtaildocs/blocks.py b/wagtail/wagtaildocs/blocks.py index e4c9c6da4..8a0c95306 100644 --- a/wagtail/wagtaildocs/blocks.py +++ b/wagtail/wagtaildocs/blocks.py @@ -22,3 +22,6 @@ class DocumentChooserBlock(ChooserBlock): return format_html('{1}', value.url, value.title) else: return '' + + class Meta: + icon = "doc-empty" diff --git a/wagtail/wagtailembeds/blocks.py b/wagtail/wagtailembeds/blocks.py index 57b3a4ad9..6caa8bde4 100644 --- a/wagtail/wagtailembeds/blocks.py +++ b/wagtail/wagtailembeds/blocks.py @@ -61,3 +61,6 @@ class EmbedBlock(blocks.URLBlock): return None else: return EmbedValue(value) + + class Meta: + icon = "media" diff --git a/wagtail/wagtailimages/blocks.py b/wagtail/wagtailimages/blocks.py index 641ad41f6..ac8394cad 100644 --- a/wagtail/wagtailimages/blocks.py +++ b/wagtail/wagtailimages/blocks.py @@ -23,3 +23,6 @@ class ImageChooserBlock(ChooserBlock): return get_rendition_or_not_found(value, 'original').img_tag() else: return '' + + class Meta: + icon = "image" diff --git a/wagtail/wagtailsnippets/blocks.py b/wagtail/wagtailsnippets/blocks.py index bf76393fe..54b89e761 100644 --- a/wagtail/wagtailsnippets/blocks.py +++ b/wagtail/wagtailsnippets/blocks.py @@ -14,3 +14,6 @@ class SnippetChooserBlock(ChooserBlock): def widget(self): from wagtail.wagtailsnippets.widgets import AdminSnippetChooser return AdminSnippetChooser(self.target_model) + + class Meta: + icon = "snippet"