add distinct icons to blocks

pull/2423/merge
Benjamin Bach 2016-02-27 14:51:38 +01:00 zatwierdzone przez Matt Westcott
rodzic b978fb826f
commit dfd8a5cc2b
11 zmienionych plików z 95 dodań i 9 usunięć

Wyświetl plik

@ -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)

Wyświetl plik

@ -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
~~~~~~~~~

Wyświetl plik

@ -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'

Wyświetl plik

@ -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

Wyświetl plik

@ -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',
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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

Wyświetl plik

@ -22,3 +22,6 @@ class DocumentChooserBlock(ChooserBlock):
return format_html('<a href="{0}">{1}</a>', value.url, value.title)
else:
return ''
class Meta:
icon = "doc-empty"

Wyświetl plik

@ -61,3 +61,6 @@ class EmbedBlock(blocks.URLBlock):
return None
else:
return EmbedValue(value)
class Meta:
icon = "media"

Wyświetl plik

@ -23,3 +23,6 @@ class ImageChooserBlock(ChooserBlock):
return get_rendition_or_not_found(value, 'original').img_tag()
else:
return ''
class Meta:
icon = "image"

Wyświetl plik

@ -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"